-
This will not be good at all if the content of a multilingual site is organized in one directory, i.e. There is another problem of bad links, but it relates to the short code 'mermaid'. If you do something like:
For site: |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 10 replies
-
So this issue is actually two. For part I: Could you give me an example repo/zip and detailed instructions how to reproduce this For part II: This is a hassle in the way Hugo generates sites and treat links. It already showed up serveral times in the past as with search and shortcode links. The implemented solution there is a bit tricky/hacky and can not be applied to this issue. So at the moment I don't have a solution for you. |
Beta Was this translation helpful? Give feedback.
-
OK, I've almost solved these problems. We will skip the last part about how the short code 'mermaid' handles links. I found a solution, but it only works for one content structure, i.e. a special case. I will make an example of a test page to reproduce and a possible version of the code a little later today. |
Beta Was this translation helpful? Give feedback.
-
As mentioned in #147: For part I: That's a Hugo "issue" - if at least. I doubt that Hugo knows something about your headings/fragment identifiers and therefore has no chance to warn for it. |
Beta Was this translation helpful? Give feedback.
-
Let's try to understand the code that exists today. {{- if in (.Get 0) "/_index.md" -}}
{{- $paths := (split (.Get 0) "_index.md") -}}
{{- $pagepath := index $paths 0 -}}
{{- $anchor := index $paths 1 -}}
{{- with .Site.GetPage "section" (trim $pagepath "/") -}}
{{- ( printf "%s%s" $pagepath $anchor ) | relLangURL -}}
{{- end -}}
{{- else -}}
{{- with .Site.GetPage "section" (.Get 0) }}
{{- .RelPermalink -}}
{{- else -}}
{{- .Get 0 | relref .Page -}}
{{- end -}}
{{- end -}} The first condition is a special case for a sequence of characters Next, inside the condition, we initialize two variables {{- else -}}
{{- with .Site.GetPage "section" (.Get 0) }} This construction is performed if we have received an html page ready for publication and inside the condition we are on the territory of this page and all its attributes, including content, are available to us. But
This line will return the correct link to the page only. All of the above can be checked using a debugging short code: <!-- First we need to initialize the necessary variables -->
{{ $hurl := (.Site.BaseURL) }}
<!-- current path for debugging -->
{{ $curpathf := $.Page.File}}
<!-- Split the file path and the ID key -->
{{ $spls := (split (.Get 0) "#") }}
<!-- We will print it for verification -->
{{ $anchor := index $spls 1 }}
{{ $pagepath := index $spls 0 }}
{{- printf "\n* [ Get 0 = %s ]\n" (.Get 0) -}}
{{- printf "\n* [ BaseURL = %s ]\n" $hurl -}}
{{- printf "* [ relURL = %s ]\n" ( $hurl | relURL ) -}}
{{- printf "* [ anchor = %s ]\n" $anchor -}}
{{- printf "* [ current path Page = %s ]\n" $curpathf -}}
<!-- Get the page if it exists -->
{{- with .Site.GetPage $pagepath -}}
{{- printf "( .Site.GetPage %s = TRUE )\n\n" $pagepath -}}
<!-- Get the Anchor if it exists in page -->
{{- if in ( .Content ) $anchor -}}
{{- printf "* Anchor \"%s\" is exsist\n\n" $anchor -}}
{{- else -}}
{{ warnf "Do not get anchor [%s] for page [%s]" $anchor $pagepath }}
{{- printf "* Anchor \"%s\" is **not** exist\n\n" $anchor -}}
{{- end -}}
{{- else -}}
{{ warnf "Do not get page with [%s] argument" $pagepath }}
{{- end -}}
{{- printf "%s\n" "---" -}}
{{- with .Site.GetPage $pagepath -}}
{{- printf "* %s\n" (findRE "<h2.*?>(.|\n)*?</h2>" (.Content)) -}}
{{- end -}}
{{- printf "%s\n" "---" -}} |
Beta Was this translation helpful? Give feedback.
-
I still have an open question how to display "broken" bad links. Whether or not they can be colored red, if the code returns a link to the page from which it was called. |
Beta Was this translation helpful? Give feedback.
-
Add an additional check for the existence of an anchor in the index. <!-- First we need to initialize the necessary variables -->
{{ $hurl := (.Site.BaseURL) }}
<!-- current path for debugging -->
{{ $curpathf := $.Page.File}}
<!-- Split the file path and the ID key -->
{{ $spls := (split (.Get 0) "#") }}
<!-- We will print it for verification -->
{{ $anchor := index $spls 1 }}
{{ $pagepath := index $spls 0 }}
{{- printf "\n* [ Get 0 = %s ]\n" (.Get 0) -}}
{{- printf "\n* [ BaseURL = %s ]\n" $hurl -}}
{{- printf "* [ relURL = %s ]\n" ( $hurl | relURL ) -}}
{{- printf "* [ anchor = %s ]\n" $anchor -}}
{{- printf "* [ current path Page = %s ]\n" $curpathf -}}
<!-- Get the page if it exists -->
{{- with .Site.GetPage $pagepath -}}
{{- printf "( .Site.GetPage %s = TRUE )\n\n" $pagepath -}}
<!-- Get the Anchor if it exists in page -->
{{- if index $spls 1 -}}
{{- printf "* The anchor [ %s ] on the chapter exists and can be checked\n" $anchor -}}
{{- if in ( .Content ) $anchor -}}
{{- printf "* Anchor \"%s\" is exsist\n\n" $anchor -}}
{{- else -}}
{{ warnf "Do not get anchor [%s] for page [%s]" $anchor $pagepath }}
{{- printf "* Anchor \"%s\" is **not** exist\n\n" $anchor -}}
{{- end -}}
{{- else -}}
{{- printf "* The anchor on the chapter **DOES NOT** exist. There is no need to check\n" -}}
{{- end -}}
{{- else -}}
{{ warnf "Do not get page with [%s] argument" $pagepath }}
{{- end -}}
{{- printf "%s\n" "---" -}}
{{- with .Site.GetPage $pagepath -}}
{{- printf "* %s\n" (findRE "<h2.*?>(.|\n)*?</h2>" (.Content)) -}}
{{- end -}}
{{- printf "%s\n" "---" -}} |
Beta Was this translation helpful? Give feedback.
-
@McShelby Yesterday I finished my version of the This code works well on your example site and for a small number of translated pages of the site I'm currently working on. I have a large number of cross-references. And links to anchors that are generated during page rendering, i.e. they are not in the source file, but the author has indicated links to them. And this is a really big problem. |
Beta Was this translation helpful? Give feedback.
-
I've created issue #156 out of this discussion. Sadly it did not convert the discussion to issue comments. |
Beta Was this translation helpful? Give feedback.
-
The opened issue ended in a breaking change. I've added extensive migration instructions to the documentation with the essentials of this conversation. |
Beta Was this translation helpful? Give feedback.
So this issue is actually two.
For part I: Could you give me an example repo/zip and detailed instructions how to reproduce this
For part II: This is a hassle in the way Hugo generates sites and treat links. It already showed up serveral times in the past as with search and shortcode links. The implemented solution there is a bit tricky/hacky and can not be applied to this issue. So at the moment I don't have a solution for you.