Giter Club home page Giter Club logo

portable-hugo-links's Introduction

This is test repo to test out the new Markdown Render Hooks in Hugo 0.62.0, to demonstrate truly portable Markdown links and images. No shortcodes used.

This means that Markdown links/images should work whether browsed on GitHub or the Hugo site on Netlify.

Note that this project needs Hugo >= 0.62.1 to run.




portable-hugo-links's People

Contributors

bep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

portable-hugo-links's Issues

Simplification of render-link template

I was playing around with your render-link template, and came up with a somewhat simpler version of the code used to derive the final link value that you might want to use:

{{- $link := .Destination }}
{{- $url := urls.Parse $link }}
{{- $isRemote := $url.IsAbs }}
{{- if and (not $isRemote) (strings.HasSuffix $url.Path ".md") }}
  {{- $link = relref .Page $link }}
{{- end -}}

Here I'm using the parsed URL to determine whether the link is a local markdown link, and the relref function to convert that to the relative location of that page. This handles fragments for us, and generates a nice error message if the page cannot be found.

In-page anchor support?

I tried to use the example here. It works great for links with anchor to another page, but if I use an anchor to this page, such as a link [like](#this), it does not work correctly.

Consider add support and some example?

I am new to hugo, and I tried to make some modifications:

{{ $link := .Destination }}
{{ $isRemote := strings.HasPrefix $link "http" }}
{{- if not $isRemote -}}
  {{ $url := urls.Parse .Destination }}
  {{ $fragment := "" }}
  {{- with $url.Fragment }}{{ $fragment = printf "#%s" . }}{{ end -}}
  {{- if $url.Path -}}{{/* ensure it referring to another page */}}
    {{- with .Page.GetPage $url.Path }}{{ $url.Path }}{{ $link = printf "%s%s" .RelPermalink $fragment }}{{.Permalink}}{{ end }}
  {{- else -}}
    {{ $link = $fragment }}
  {{ end }}
{{ end -}}
<a href="{{ $link | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if $isRemote }} target="_blank"{{ end }}>{{ .Text | safeHTML }}</a>

Example using anchors?

I was trying use render-links example here with anchors, but that doesn't seem to work. For the regular page the relative URL works (yay), but not for those using anchors. Looking at what gets generated I see a nopPage for .relPermalink returned for the link with anchor.

I'm not sure if there may be some config that is wrong my side, or if relative links with anchors need to be specially handled.

why isn't this the default Hugo behaviour?

thank you for this, because i was struggling to edit and manage tons of content via VSCode/Obsidian
and i need to keep markdown readability, so the links have to be kept in md format

but why isn't this a default behaviour? or a config enabled option?

are there any problems if i keep these links?

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.