From 11debae8d4a683f3e7281619284cd73c54d3978a Mon Sep 17 00:00:00 2001 From: Duccio Gasparri <553197+dgasparri@users.noreply.github.com> Date: Sat, 12 Nov 2022 10:17:24 +0100 Subject: [PATCH] =?UTF-8?q?Cleaned=20Use=20of=20ref=20and=20relref=20secti?= =?UTF-8?q?on,=20added=20refs=20of=20index.md=20and=20=5Fin=E2=80=A6=20(#1?= =?UTF-8?q?744)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Cleaned Use of ref and relref section, added refs of index.md and _index.md See https://discourse.gohugo.io/t/ref-relref-error/18904/3 Co-authored-by: Joe Mooring --- .../en/content-management/cross-references.md | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/content/en/content-management/cross-references.md b/content/en/content-management/cross-references.md index 5ec7dc545..151b91514 100644 --- a/content/en/content-management/cross-references.md +++ b/content/en/content-management/cross-references.md @@ -17,15 +17,35 @@ toc: true The `ref` and `relref` shortcodes display the absolute and relative permalinks to a document, respectively. -## Use `ref` and `relref` +## Use of `ref` and `relref` -```go-html-template -{{}} -{{}} -{{}} -{{}} -{{}} -{{}} +The `ref` and `relref` shortcodes require a single parameter: the path to a content document, with or without a file extension, with or without an anchor. Paths without a leading `/` are first resolved relative to the current page, then to the remainder of the site. + +``` +. +└── content + ├── about + | ├── _index.md + | └── credits.md + ├── pages + | ├── document1.md + | └── document2.md // has anchor #anchor + ├── products + | └── index.md + └── blog + └── my-post.md +``` + +The pages can be referenced as follows: + + +```text +{{}} // <- From pages/document1.md, relative path +{{}} +{{}} +{{}} +{{}} // <- From pages/document2.md +{{}} // <- From anywhere, absolute path {{}} {{}} {{}} @@ -33,15 +53,22 @@ The `ref` and `relref` shortcodes display the absolute and relative permalinks t {{}} ``` -To generate a hyperlink using `ref` or `relref` in markdown: +index.md can be reference either by its path or by its containing folder without the ending `/`. \_index.md can be referenced only by its containing folder: -```md -[About]({{}} "About Us") +```text +{{}} // <- References /about/_index.md +{{}} // Raises REF_NOT_FOUND error +{{}} // <- References /about/credits.md + +{{}} // <- References /products/index.md +{{}} // <- References /products/index.md ``` -The `ref` and `relref` shortcodes require a single parameter: the path to a content document, with or without a file extension, with or without an anchor. +To generate a hyperlink using `ref` or `relref` in markdown: -**Paths without a leading `/` are first resolved relative to the current page, then to the remainder of the site. +```text +[About]({{}} "About Us") +``` Hugo emits an error or warning if a document cannot be uniquely resolved. The error behavior is configurable; see below.