zola/docs/content/documentation/content/linking.md
photong 51d4b6bd6a Simple clean up of documentation. (#849)
* Update installation.md

* Update cli-usage.md

* Update installation.md

* Update directory-structure.md

* Update configuration.md

* Update overview.md

* Update section.md

* Update page.md

* Update section.md

* Update configuration.md

* Update page.md

* Update section.md

* Update page.md

* Update shortcodes.md

* Update linking.md

* Update table-of-contents.md

* Update syntax-highlighting.md

* Update taxonomies.md

* Update search.md

* Update sass.md

* Update index.md

* Update multilingual.md

* Update overview.md

* Update pages-sections.md

* Update pagination.md

* Update taxonomies.md

* Update rss.md

* Update sitemap.md

* Update robots.md

* Update 404.md

* Update archive.md

* Update overview.md

* Update installing-and-using-themes.md

* Update creating-a-theme.md

* Update netlify.md

* Update github-pages.md

* Update gitlab-pages.md

* Update index.md

* Update page.md

* Update section.md

* Updates.
2020-02-02 17:48:42 -08:00

2 KiB

+++ title = "Internal links & deep linking" weight = 50 +++

Heading id and anchor insertion

While rendering the Markdown content, a unique id will automatically be assigned to each heading. This id is created by converting the heading text to a slug, and appending numbers at the end if the slug already exists for that article. For example:

# Something exciting! <- something-exciting
## Example code <- example-code

# Something else <- something-else
## Example code <- example-code-1

You can also manually specify an id with a {#…} suffix on the heading line:

# Something manual! {#manual}

This is useful for making deep links robust, either proactively (so that you can later change the text of a heading without breaking links to it) or retroactively (keeping the slug of the old header text when changing the text). It can also be useful for migration of existing sites with different header id schemes, so that you can keep deep links working.

Anchor insertion

It is possible to have Zola automatically insert anchor links next to the heading, as you can see on this site if you hover a title.

This option is set at the section level: the insert_anchor_links variable on the section front matter page.

The default template is very basic and will need CSS tweaks in your project to look decent. If you want to change the anchor template, it can be easily overwritten by creating an anchor-link.html file in the templates directory, which gets an id variable.

Linking to other pages and their headings is so common that Zola adds a special syntax to Markdown links to handle them: start the link with @/ and point to the .md file you want to link to. The path to the file starts from the content directory.

For example, linking to a file located at content/pages/about.md would be [my link](@/pages/about.md). You can still link to an anchor directly; [my link](@/pages/about.md#example) will work as expected.