Struggling with hyperlinks

Repo: GitHub - chrisxfire/chrisxfire.github.io

I’ve been trying to use Markdown-style links with Hugo. I have a layouts/_default/_markup/render-link.html and a layouts/_default/_markup/render-image.html.

Consider the page at /notes/asp.net/fundamentals/services-and-dependency-injection/.
On that page, the second hyperlink attempts to link to:

/notes/_net/dependency-injection/overview.md

The Markdown for that hyperlink is…

[Dependency Injection in .NET](../../_net/dependency-injection/overview)

…which instead links to:

/notes/asp.net/_net/dependency-injection/overview

If I change the Markdown to…

[Dependency Injection in .NET](/notes/_net/dependency-injection/overview)

…it works. However, this is unintuitive because /notes is not the root of the repo. Below /notes is /content, so intuitively it would be /content/notes/...

Of course, links to documents not below the /notes/asp.net/ level work fine.

I don’t understand Hugo Markdown render hooks well enough to fix this. Does anyone have any advice?

Without a render hook, you’re asking the browser to do this:

http://localhost:1314/notes/asp.net/fundamentals/services-and-dependency-injection/../../_net/dependency-injection/overview

Which resolves to this:

http://localhost:1314/notes/asp.net/_net/dependency-injection/overview

Which is a 404.

Hugo publishes your site like this:

public/
├── notes/  <--------------------------------------- UP THREE LEVELS ../../..
│   ├── _net/
│   │   ├── dependency-injection/
│   │   │   ├── overview/
│   │   │   │   └── index.html
│   │   │   └── index.html
│   │   └── index.html
│   ├── asp.net/ <---------------------------------- UP TWO LEVELS ../..
│   │   ├── fundamentals/  <------------------------ UP ONE LEVEL ../
│   │   │   └── services-and-dependency-injection/
│   │   │       └── index.html  <------------------- START HERE
│   │   └── index.html
│   └── index.html
└── index.html

You want to do this:

http://localhost:1314/notes/asp.net/fundamentals/services-and-dependency-injection/../../../_net/dependency-injection/overview

Which resolves to this:

http://localhost:1314/notes/_net/dependency-injection/overview/

This article might be helpful.

Wouldn’t ref or relref simplify that? Something like

[Dependency Injection in .NET]({{<ref "Dependency Injection in .NET">}})

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.