I was using a lot of relative links in my note on GitHub.
I am planning to use hugo to build a static page’s version.
But my note has a lot of links like this:
root-of-the-repositorie/README.md:
[page 1](./balabala/page1.md)
[something in page 1](./balabala/page1.md#something)
Hugo seems cannot process this kind of link, it will generate URL ends with .md.
The link usually looks like this:
markdown file path: root-of-the-repositorie/art/README.md
hugo generated link: http://127.0.0.1/art/README/
but if I clik the link in this page: [balabala](./balabala/balaBala.md)
hugo will cover this URL to:
http://127.0.0.1/art/README/balabala/balaBala.md
The README will stay in the URL and never goes away.
And I noticed that hugo will cover root-of-the-repositorie/balabala/README.md to /public/balabala/readme/index.html
Is there any easy way to cover these links to some format that hugo can process?
Is any way to just cover README.md to the default page(index.html)?
Is any good way to make markdown links works well with hugo and GitHub at the same time?
This is a detailed example of a render hook for links. It looks first for a page, then for a page resource (example: a PDF file), then a global resource.
{{- $attrs := dict }}
{{- $u := urls.Parse .Destination }}
{{- if $u.IsAbs }}
{{- /* Remote */}}
{{- $attrs = dict "href" $u.String "rel" "external" }}
{{- else }}
{{- with $u.Path }}
{{- with $.Page.GetPage . }}
{{- /* Page */}}
{{- $href := .RelPermalink }}
{{- with $u.RawQuery }}
{{- $href = printf "%s?%s" $href $u.RawQuery }}
{{- end }}
{{- with $u.Fragment }}
{{- $href = printf "%s#%s" $href $u.Fragment }}
{{- end }}
{{- $attrs = dict "href" $href }}
{{- else }}
{{- with $.Page.Resources.GetMatch $u.Path }}
{{- /* Page resource; drop query and fragment */}}
{{- $attrs = dict "href" .RelPermalink }}
{{- else }}
{{- with resources.Get $u.Path }}
{{- /* Global resource; drop query and fragment */}}
{{- $attrs = dict "href" .RelPermalink }}
{{- else }}
{{- errorf "Unable to resolve reference to %s from %s" $u.Path $.Page.File.Path }}
{{- end }}
{{- end }}
{{- end }}
{{- else }}
{{- with $u.Fragment }}
{{- /* Fragment only; prepend page's relative permalink */}}
{{- $attrs = dict "href" (printf "%s#%s" $.Page.RelPermalink .) }}
{{- else }}
{{- errorf "Unable to resolve reference to %s from %s" $u.Path $.Page.File.Path }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Title }}
{{- $attrs = merge $attrs (dict "title" .) }}
{{- end -}}
<a
{{- range $k, $v := $attrs }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end -}}
>{{ .Text | safe.HTML }}</a>
{{- /**/ -}}
To use the README.md in the root of your project directory as your home page content, create a symbolic link from content/_index.md to the README.md file.