Skip to content

Commit

Permalink
hugo: shortcode linkto/related/*
Browse files Browse the repository at this point in the history
This adds 4 shortcodes that generate consistently formatted links to
concept guides, howto guides, references, and tutorials. Their formatted
output is intended for use inside pages' Related content sections, with
the intention to replace all current manually-formatted links in these
sections with uses of these shortcodes, site wide.

Preview-Path: /examples/shortcodes/linkto/
Signed-off-by: Jonathan Matthews <[email protected]>
Change-Id: Ia74ca0e8eca3c8e1e1d9dc0f35e16ccac87075e2
Dispatch-Trailer: {"type":"trybot","CL":1176797,"patchset":1,"ref":"refs/changes/97/1176797/1","targetBranch":"alpha"}
  • Loading branch information
jpluscplusm authored and cueckoo committed Feb 13, 2024
1 parent baed24e commit 16bc4e5
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 10 deletions.
15 changes: 10 additions & 5 deletions content/examples/_en.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,21 @@ <h1 class="section__title">Examples</h1>
<p class="nav__title">Shortcodes</p>

<ul class="nav__list">
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/issue/">
<span class="nav__text">GitHub issue (<code>cue-lang/cue</code>)</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/info/">
<span class="nav__text">Info Block</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/linkto/">
<span class="nav__text">LinkTo</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/param/">
<span class="nav__text">Param</span>
Expand All @@ -130,11 +140,6 @@ <h1 class="section__title">Examples</h1>
<span class="nav__text">Sidenote</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/issue/">
<span class="nav__text"><code>cue-lang/cue</code> GitHub issue</span>
</a>
</li>
</ul>
</div>

Expand Down
40 changes: 40 additions & 0 deletions content/examples/shortcodes/linkto/en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: linkto
---

The `linkto` hierarchy contains convenience shims that generate well-formed and
consistently formatted links to commonly referenced pages.

### `linkto/related/{concept,howto,reference,tutorial}`

`linkto/related/` contains 4 shortcodes primarily aimed at generating links to
Tutorials, How-to Guides, Concept Guides, and References. The links contain the
linked-to page's title field. They are intended to be used in a page's "Related
content" section, placed inside a list element. They only generate content
suitable for inclusion in a list, and do not generate self-contained list
elements.

Only these 4 hierarchies are currently supported as they make up the majority
of related content links, and have reduced implementation complexity (relative
to, say, linking to the Language Guide or the Tour) due to their flat page
hierarchies.

#### Parameters

The first positional parameter is the path component of the related page
**within** the relevant hierarchy. I.e. **without** a leading "docs/tutorial/",
"docs/reference/", etc.

#### Examples

```
- {{</* linkto/related/concept "the-logic-of-cue" */>}}
- {{</* linkto/related/howto "use-strings-replace" */>}}
- {{</* linkto/related/reference "modules" */>}}
- {{</* linkto/related/tutorial "working-with-a-custom-module-registry" */>}}
```

- {{< linkto/related/concept "the-logic-of-cue" >}}
- {{< linkto/related/howto "use-strings-replace" >}}
- {{< linkto/related/reference "modules" >}}
- {{< linkto/related/tutorial "working-with-a-custom-module-registry" >}}
3 changes: 3 additions & 0 deletions content/examples/shortcodes/linkto/page.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package site

content: examples: shortcodes: linkto: {}
15 changes: 10 additions & 5 deletions hugo/content/en/examples/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,21 @@ <h1 class="section__title">Examples</h1>
<p class="nav__title">Shortcodes</p>

<ul class="nav__list">
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/issue/">
<span class="nav__text">GitHub issue (<code>cue-lang/cue</code>)</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/info/">
<span class="nav__text">Info Block</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/linkto/">
<span class="nav__text">LinkTo</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/param/">
<span class="nav__text">Param</span>
Expand All @@ -130,11 +140,6 @@ <h1 class="section__title">Examples</h1>
<span class="nav__text">Sidenote</span>
</a>
</li>
<li class="nav__item">
<a class="nav__link" href="/examples/shortcodes/issue/">
<span class="nav__text"><code>cue-lang/cue</code> GitHub issue</span>
</a>
</li>
</ul>
</div>

Expand Down
40 changes: 40 additions & 0 deletions hugo/content/en/examples/shortcodes/linkto/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: linkto
---

The `linkto` hierarchy contains convenience shims that generate well-formed and
consistently formatted links to commonly referenced pages.

### `linkto/related/{concept,howto,reference,tutorial}`

`linkto/related/` contains 4 shortcodes primarily aimed at generating links to
Tutorials, How-to Guides, Concept Guides, and References. The links contain the
linked-to page's title field. They are intended to be used in a page's "Related
content" section, placed inside a list element. They only generate content
suitable for inclusion in a list, and do not generate self-contained list
elements.

Only these 4 hierarchies are currently supported as they make up the majority
of related content links, and have reduced implementation complexity (relative
to, say, linking to the Language Guide or the Tour) due to their flat page
hierarchies.

#### Parameters

The first positional parameter is the path component of the related page
**within** the relevant hierarchy. I.e. **without** a leading "docs/tutorial/",
"docs/reference/", etc.

#### Examples

```
- {{</* linkto/related/concept "the-logic-of-cue" */>}}
- {{</* linkto/related/howto "use-strings-replace" */>}}
- {{</* linkto/related/reference "modules" */>}}
- {{</* linkto/related/tutorial "working-with-a-custom-module-registry" */>}}
```

- {{< linkto/related/concept "the-logic-of-cue" >}}
- {{< linkto/related/howto "use-strings-replace" >}}
- {{< linkto/related/reference "modules" >}}
- {{< linkto/related/tutorial "working-with-a-custom-module-registry" >}}
9 changes: 9 additions & 0 deletions hugo/layouts/shortcodes/linkto/related/concept.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ $relPath := printf "docs/concept/%s" (.Get 0) -}}
{{ $linkToPage := site.GetPage $relPath -}}
{{- if eq (strings.CountRunes $linkToPage.Title) 0 -}}
{{ errorf "[%s] %q: %q not found or has no title" site.Language.Lang .Page.File $relPath }}
{{- end -}}
Concept Guide: {{ with $linkToPage -}}
{{- $opts := dict "path" $relPath -}}
<a href="{{ .RelRef $opts }}">{{ .Title }}</a>
{{- end}}
9 changes: 9 additions & 0 deletions hugo/layouts/shortcodes/linkto/related/howto.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ $relPath := printf "docs/howto/%s" (.Get 0) -}}
{{ $linkToPage := site.GetPage $relPath -}}
{{- if eq (strings.CountRunes $linkToPage.Title) 0 -}}
{{ errorf "[%s] %q: %q not found or has no title" site.Language.Lang .Page.File $relPath }}
{{- end -}}
How-to Guide: {{ with $linkToPage -}}
{{- $opts := dict "path" $relPath -}}
<a href="{{ .RelRef $opts }}">{{ .Title }}</a>
{{- end}}
9 changes: 9 additions & 0 deletions hugo/layouts/shortcodes/linkto/related/reference.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ $relPath := printf "docs/reference/%s" (.Get 0) -}}
{{ $linkToPage := site.GetPage $relPath -}}
{{- if eq (strings.CountRunes $linkToPage.Title) 0 -}}
{{ errorf "[%s] %q: %q not found or has no title" site.Language.Lang .Page.File $relPath }}
{{- end -}}
Reference: {{ with $linkToPage -}}
{{- $opts := dict "path" $relPath -}}
<a href="{{ .RelRef $opts }}">{{ .Title }}</a>
{{- end}}
9 changes: 9 additions & 0 deletions hugo/layouts/shortcodes/linkto/related/tutorial.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ $relPath := printf "docs/tutorial/%s" (.Get 0) -}}
{{ $linkToPage := site.GetPage $relPath -}}
{{- if eq (strings.CountRunes $linkToPage.Title) 0 -}}
{{ errorf "[%s] %q: %q not found or has no title" site.Language.Lang .Page.File $relPath }}
{{- end -}}
Tutorial: {{ with $linkToPage -}}
{{- $opts := dict "path" $relPath -}}
<a href="{{ .RelRef $opts }}">{{ .Title }}</a>
{{- end}}

0 comments on commit 16bc4e5

Please sign in to comment.