ilink shortcode: use unique numbers for ids (backlink anchors)
This commit is contained in:
		
							parent
							
								
									11748e3be8
								
							
						
					
					
						commit
						812c15df93
					
				
					 2 changed files with 5 additions and 3 deletions
				
			
		|  | @ -3,7 +3,7 @@ | |||
| module: | ||||
|   hugoVersion: | ||||
|     extended: true | ||||
|     min: 0.91.2 | ||||
|     min: 0.115.1 | ||||
| 
 | ||||
| frontmatter: | ||||
|   date: | ||||
|  | @ -24,6 +24,7 @@ related: | |||
| 
 | ||||
| # non-standard: escaped JSON lines | ||||
| # with \\n and \\t for import to PostgreSQL jsonb column | ||||
| # see `sql` directory | ||||
| mediaTypes: | ||||
|   x-text/ejsonl: | ||||
|     suffixes: | ||||
|  | @ -35,4 +36,3 @@ outputFormats: | |||
|     isPlainText: true | ||||
|     mediaType: x-text/ejsonl | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,13 +1,15 @@ | |||
| {{- $pid := or (.Get "pid") (.Get "page") -}} | ||||
| {{- $frag := or (.Get "id") (.Get "anchor") -}} | ||||
| {{- $this := $.Page -}} | ||||
| {{- $linkid := or ($this.Scratch.Get "linkid") 1 -}} | ||||
| {{- $this.Scratch.Set "linkid" (add $linkid 1) -}} | ||||
| {{- $pages := where .Site.RegularPages "Params.pageid" "eq" $pid -}} | ||||
| {{- $fragsep := cond (eq $frag "") "" "#" -}} | ||||
| {{- $inner := .Inner -}} | ||||
| {{- range $pages -}} | ||||
|   {{- $url := printf "%s%s%s" .Permalink $fragsep $frag -}} | ||||
|   {{- $text := or $inner .Title -}} | ||||
|   {{- $anchor := $text | anchorize -}} | ||||
|   {{- $anchor := printf "link-%d" $linkid -}} | ||||
|   <a id="{{ $anchor }}" | ||||
|      href="{{ $url }}">{{ $text | markdownify }}</a> | ||||
|   {{- .Scratch.Add "backlinks" (slice (dict "anchor" $anchor "page" $this)) -}} | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue