How can I convert markdown files contains relative link with end with *.md to hugo links?

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?

You cannot use markdown into markdown in such way.

When Hugo generating pages it using markdown files to generate html output (or other)

If you want to link to other page, you need to link to page URL as if it was live website.

That’s the Markdown way, not Hugo.

The Hugo method is described here

Example

{{< ref "document2.md#anchor" >}} 
1 Like

You can accommodate portable links with a markdown render hook.

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.

mkdir -p layouts/_default/_markup
touch layouts/_default/_markup/render-link.html
layouts/_default/_markup/render-link.html
{{- $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.

cd content
ln -s ../README.md _index.md 
cd ..
1 Like

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