Automatic Internal Linking based on Keywords


I am pretty new to Hugo and would like to learn more about building sites with it. Currently I am wondering if I am able to define in a Markdown file for example Internal-Links: {keyword: kw1, url: /page1}, {keyword: kw2, url: /page2 etc., have Hugo when building the site check the content body of the Markdown file for those keywords and have those found keywords converted to links to other pages. The goal is trying to have a somewhat automatic internal linking of blog pages based on defined keywords/tags and have hugo automatically inject the links into the content.

Thank you for any help and replies - highly appreciated.

Not entirely sure about how you could configure the automatic part of your question.

Have a look at: Links and Cross References | Hugo

Also the function relref | Hugo

A hacky workflow that comes to mind, would be to:

  • Store an array of these keywords in a parameter of the project’s config.
  • Use the replace or replaceRE functions to check up the .Content of Single Pages
  • When encountered, the keywords will be wrapped in HTML links markup, that will point to a Related Content File.
  • However since there may be more than one Related Content links you would most likely need to pick a single one (at random) by piping the Related Content links with the uniq function.

It would be quite complicated even for me to put the above together and I am only spitballing here.

I don’t think that as beginner you want to follow that path, also because depending on a project’s size the above may slow down the project build time (or it may not).

Perhaps others can offer more informed suggestions to your question.


@alexandros thank you very much for taking the time to answer my question, highly appreciated. relref is a good start indeed to parse the permalinks. Currently I was thinking to use the replaceRE function for finding the keywords and replace them with the URL and fund the regex/replace pattern via the template variables from the