Code Monkey home page Code Monkey logo

Comments (4)

zoni avatar zoni commented on June 5, 2024 2

The problem here is Hugo. Not to pick on Hugo too much, I use it too and really like it in general, but in this regard I find its behavior quite unfortunate. Hugo expects you to use ref and relref shortcodes instead of using regular Markdown link syntax to sibling content files.

(If you try the exact same file layout with MkDocs, you'll find it works out of the box without issue)

I've found that Markdown Render Hooks allow us to work around the issue (make sure you're using goldmark as your renderer).

Create the file layouts/_default/_markup/render-link.html with the following contents:

{{- $url := urls.Parse .Destination -}}
{{- $scheme := $url.Scheme -}}

<a href="
  {{- if eq $scheme "" -}}
    {{- if strings.HasSuffix $url.Path ".md" -}}
      {{- relref .Page .Destination | safeURL -}}
    {{- else -}}
      {{- .Destination | safeURL -}}
    {{- end -}}
  {{- else -}}
    {{- .Destination | safeURL -}}
  {{- end -}}"
  {{- with .Title }} title="{{ . | safeHTML }}"{{- end -}}>
  {{- .Text | safeHTML -}}
</a>

{{- /* whitespace stripped here to avoid trailing newline in rendered result caused by file EOL */ -}}

And layouts/_default/_markup/render-image.html for images:

{{- $url := urls.Parse .Destination -}}
{{- $scheme := $url.Scheme -}}

<img src="
  {{- if eq $scheme "" -}}
    {{- if strings.HasSuffix $url.Path ".md" -}}
      {{- relref .Page .Destination | safeURL -}}
    {{- else -}}
      {{- printf "/%s%s" .Page.File.Dir .Destination | safeURL -}}
    {{- end -}}
  {{- else -}}
    {{- .Destination | safeURL -}}
  {{- end -}}"
  {{- with .Title }} title="{{ . | safeHTML }}"{{- end -}}
  {{- with .Text }} alt="{{ . | safeHTML }}"
  {{- end -}}
/>

{{- /* whitespace stripped here to avoid trailing newline in rendered result caused by file EOL */ -}}

Does that resolve the issue for you?

from obsidian-export.

JeremieLitzler avatar JeremieLitzler commented on June 5, 2024 1

@zoni

Thanks for this solution. That made my day! I was horrified to have to change all native markdown links to < ref ... > or < relref ... >...

It works like a charm.

from obsidian-export.

zoni avatar zoni commented on June 5, 2024

Based on the lack of response I'm going to assume you either fixed your issue or lost interest in pursuing this.

from obsidian-export.

ikrima avatar ikrima commented on June 5, 2024

Based on the lack of response I'm going to assume you either fixed your issue or lost interest in pursuing this.

apologies for necro-ing this but ran into this same issue with mkdocs. Not too familiar with hugo but fwiw, the issue was the generated relative paths on windows were using unescaped "" as path separator

Swapping them with "/" fixed the issue. Presumably that should be the default, no? (only issue i can imagine is some static generators on Win7 that don't properly handle that as a separator)

from obsidian-export.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.