Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking pages in Hugo/markdown

Tags:

markdown

hugo

I am new to HUGO (http://gohugo.io/) static site generator. I am running Hugo server locally accessible as localhost:1313. I am trying to link pages in two different sections. My "feature.md" file need a link to "grid_modules.md" and vice versa. Following is the directory structure for both files in hugo generated site.

~/mysite/content/about/feature.md

~/mysite/content/modules/grid_modules.md

What is the best way to link both pages together? What I am trying is the following

In feature.md:

"[grid_modules] (../modules/grid_modules)"

If I try to access this link, I get an error at "localhost:1313/about/modules/grid_modules" which I know is wrong location.

What I am missing in linking? Why I am not getting "localhost:1313/modules/grid_modules" instead.

like image 752
Adeel Avatar asked Oct 19 '15 22:10

Adeel


People also ask

How do I link to another page in markdown?

Markdown syntax for a hyperlink is square brackets followed by parentheses. The square brackets hold the text, the parentheses hold the link.

What is Hugo permalink?

The permalinks option in your site configuration allows you to adjust the directory paths (i.e., the URLs) on a per-section basis. This will change where the files are written to and will change the page's internal “canonical” location, such that template references to .

Does Hugo Support markdown?

Hugo has excellent Markdown support out of the box. By default, Hugo uses the Goldmark Markdown processor which is fully CommonMark-compliant. See the configuration instructions to learn more about the extensions you can configure. You can change Hugo's Goldmark settings in the config.

What is the URL of Hugo?

Based on the standard URL of our website, Hugo knows how to build HTML hyperlinks and link to assets like image and JavaScript files. When we serve our website on our local computer with hugo server , the site's base URL looks like http://localhost:1313/ . (Hugo uses a different port when 1313 is not available.


1 Answers

This answer builds upon the answer provided by bep. That answer is correct, but not very clear (as it took me many times reading it an trying different things before I found the solution).

As stated previously:

the URL of a page depends on your URL configuration (either through in https://gohugo.io/extras/permalinks/ or set directly as the URL on the individual page).

You can use the ref and relref tags within your markdown so that a link resolves to the correct URL.

For your example, this would look like one of the following (depending on whether you want an absolute or relative URL):

[grid_modules] ( {{< relref "modules/grid_modules" >}})
[grid_modules] ( {{< ref "modules/grid_modules" >}})
like image 154
Clay Avatar answered Oct 05 '22 08:10

Clay