mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
sitemap: hide hidden pages from sitemap and SEO indexing #85
This commit is contained in:
parent
c5382e0bcc
commit
fed2e0392c
6 changed files with 90 additions and 57 deletions
|
@ -25,6 +25,8 @@ Note that some of these parameters are explained in details in other sections of
|
|||
disableSearch = false
|
||||
# Disable search in hidden pages, otherwise they will be shown in search box
|
||||
disableSearchHiddenPages = false
|
||||
# Disables hidden pages from showing up in the sitemap and on Google (et all), otherwise they may be indexed by search engines
|
||||
disableSeoHiddenPages = false
|
||||
# Javascript and CSS cache are automatically busted when new version of site is generated.
|
||||
# Set this to true to disable this behavior (some proxies don't handle well this optimization)
|
||||
disableAssetsBusting = false
|
||||
|
|
24
layouts/_default/sitemap.xml
Normal file
24
layouts/_default/sitemap.xml
Normal file
|
@ -0,0 +1,24 @@
|
|||
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
|
||||
{{- partial "page-meta.go" . }}
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
||||
{{- range .Data.Pages }}
|
||||
{{- if and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) }}
|
||||
<url>
|
||||
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
|
||||
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
|
||||
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
|
||||
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
|
||||
<xhtml:link
|
||||
rel="alternate"
|
||||
hreflang="{{ .Lang }}"
|
||||
href="{{ .Permalink }}"
|
||||
/>{{ end }}
|
||||
<xhtml:link
|
||||
rel="alternate"
|
||||
hreflang="{{ .Lang }}"
|
||||
href="{{ .Permalink }}"
|
||||
/>{{ end }}
|
||||
</url>
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
</urlset>
|
|
@ -3,8 +3,8 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
{{ hugo.Generator }}
|
||||
{{ partial "meta.html" . }}
|
||||
{{ hugo.Generator -}}
|
||||
{{- partial "meta.html" . }}
|
||||
{{ partial "favicon.html" . }}
|
||||
<title>{{ .Title }} {{ default "::" .Site.Params.titleSeparator }} {{ .Site.Title }}</title>
|
||||
|
||||
|
@ -38,58 +38,6 @@
|
|||
</style>
|
||||
{{ partial "custom-header.html" . }}
|
||||
</head>
|
||||
{{- $currentNode := . }}
|
||||
{{- $currentNode.Scratch.Set "relearnIsSelfFound" nil }}
|
||||
{{- $currentNode.Scratch.Set "relearnPrevPage" nil }}
|
||||
{{- $currentNode.Scratch.Set "relearnNextPage" nil }}
|
||||
{{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hidden" false }}
|
||||
|
||||
{{- define "relearn-structure" }}
|
||||
{{- $currentNode := .currentnode }}
|
||||
{{- $isSelf := eq $currentNode.RelPermalink .node.RelPermalink }}
|
||||
{{- $isDescendant := and (not $isSelf) (.node.IsDescendant $currentNode) }}
|
||||
{{- $isAncestor := and (not $isSelf) (.node.IsAncestor $currentNode) }}
|
||||
{{- $isOther := and (not $isDescendant) (not $isSelf) (not $isAncestor) }}
|
||||
|
||||
{{- if $isSelf }}
|
||||
{{- $currentNode.Scratch.Set "relearnIsSelfFound" true }}
|
||||
{{- end}}
|
||||
{{- $isSelfFound := eq ($currentNode.Scratch.Get "relearnIsSelfFound") true }}
|
||||
{{- $isPreSelf := and (not $isSelfFound) (not $isSelf) }}
|
||||
{{- $isPostSelf := and ($isSelfFound) (not $isSelf) }}
|
||||
|
||||
{{- $hidden_node := or (.node.Params.hidden) (eq .node.Title "") }}
|
||||
{{- $hidden_stem:= or $hidden_node .hidden }}
|
||||
{{- $hidden_from_current := or (and $hidden_node (not $isAncestor) (not $isSelf) ) (and .hidden (or $isPreSelf $isPostSelf $isDescendant) ) }}
|
||||
{{- .node.Scratch.Set "relearnIsHiddenNode" $hidden_node}}
|
||||
{{- .node.Scratch.Set "relearnIsHiddenStem" $hidden_stem}}
|
||||
|
||||
{{- if not $hidden_from_current }}
|
||||
{{- if $isPreSelf }}
|
||||
{{- $currentNode.Scratch.Set "relearnPrevPage" .node }}
|
||||
{{- else if and $isPostSelf (eq ($currentNode.Scratch.Get "relearnNextPage") nil) }}
|
||||
{{- $currentNode.Scratch.Set "relearnNextPage" .node }}
|
||||
{{- end}}
|
||||
{{- end }}
|
||||
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" .node.Pages }}
|
||||
{{- if .node.IsHome}}
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" .node.Sections }}
|
||||
{{- else if .node.Sections}}
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" (.node.Pages | union .node.Sections) }}
|
||||
{{- end}}
|
||||
{{- $pages := ($currentNode.Scratch.Get "relearnSubPages") }}
|
||||
|
||||
{{- if eq .Site.Params.ordersectionsby "title"}}
|
||||
{{- range $pages.ByTitle }}
|
||||
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hidden" $hidden_from_current }}
|
||||
{{- end}}
|
||||
{{- else}}
|
||||
{{- range $pages.ByWeight }}
|
||||
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hidden" $hidden_from_current }}
|
||||
{{- end}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
<body class="" data-url="{{ .RelPermalink }}">
|
||||
{{ partial "menu.html" . }}
|
||||
<section id="body">
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
{{ $alwaysopen := .alwaysopen }}
|
||||
{{ with $currentNode.File }}{{ $currentFileUniqueID = .UniqueID }}{{ end }}
|
||||
{{with .sect}}
|
||||
{{ $hidden := and (eq (.Scratch.Get "relearnIsHiddenStem") true) (not $.showhidden) (not (.IsAncestor $currentNode))}}
|
||||
{{ $hidden := and (eq (.Scratch.Get "relearnIsHiddenFromCurrent") true) (not $.showhidden) (not (.IsAncestor $currentNode))}}
|
||||
{{if $hidden }}
|
||||
{{else if .IsSection }}
|
||||
{{safeHTML .Params.head}}
|
||||
|
|
|
@ -1,2 +1,8 @@
|
|||
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}">
|
||||
{{ with .Site.Params.author }}<meta name="author" content="{{ . }}">{{ end }}
|
||||
{{- partial "page-meta.go" . }}
|
||||
{{- if not (and .Title (or (ne (.Scratch.Get "relearnIsHiddenStem") true) (ne .Site.Params.disableSeoHiddenPages true) ) ) }}
|
||||
<meta name="robots" content="noindex, nofollow, noarchive, noimageindex">
|
||||
{{- end }}
|
||||
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}">
|
||||
{{- with .Site.Params.author }}
|
||||
<meta name="author" content="{{ . }}">
|
||||
{{- end }}
|
53
layouts/partials/page-meta.go
Normal file
53
layouts/partials/page-meta.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
{{- $currentNode := . }}
|
||||
{{- $currentNode.Scratch.Set "relearnIsSelfFound" nil }}
|
||||
{{- $currentNode.Scratch.Set "relearnPrevPage" nil }}
|
||||
{{- $currentNode.Scratch.Set "relearnNextPage" nil }}
|
||||
{{- template "relearn-structure" dict "node" .Site.Home "currentnode" $currentNode "hiddenstem" false "hiddencurrent" false }}
|
||||
{{- define "relearn-structure" }}
|
||||
{{- $currentNode := .currentnode }}
|
||||
{{- $isSelf := eq $currentNode.RelPermalink .node.RelPermalink }}
|
||||
{{- $isDescendant := and (not $isSelf) (.node.IsDescendant $currentNode) }}
|
||||
{{- $isAncestor := and (not $isSelf) (.node.IsAncestor $currentNode) }}
|
||||
{{- $isOther := and (not $isDescendant) (not $isSelf) (not $isAncestor) }}
|
||||
|
||||
{{- if $isSelf }}
|
||||
{{- $currentNode.Scratch.Set "relearnIsSelfFound" true }}
|
||||
{{- end}}
|
||||
{{- $isSelfFound := eq ($currentNode.Scratch.Get "relearnIsSelfFound") true }}
|
||||
{{- $isPreSelf := and (not $isSelfFound) (not $isSelf) }}
|
||||
{{- $isPostSelf := and ($isSelfFound) (not $isSelf) }}
|
||||
|
||||
{{- $hidden_node := or (.node.Params.hidden) (eq .node.Title "") }}
|
||||
{{- $hidden_stem:= or $hidden_node .hiddenstem }}
|
||||
{{- $hidden_current_stem:= or $hidden_node .hiddencurrent }}
|
||||
{{- $hidden_from_current := or (and $hidden_node (not $isAncestor) (not $isSelf) ) (and .hiddencurrent (or $isPreSelf $isPostSelf $isDescendant) ) }}
|
||||
{{- .node.Scratch.Set "relearnIsHiddenNode" $hidden_node}}
|
||||
{{- .node.Scratch.Set "relearnIsHiddenStem" $hidden_stem}}
|
||||
{{- .node.Scratch.Set "relearnIsHiddenFromCurrent" $hidden_current_stem}}
|
||||
|
||||
{{- if not $hidden_from_current }}
|
||||
{{- if $isPreSelf }}
|
||||
{{- $currentNode.Scratch.Set "relearnPrevPage" .node }}
|
||||
{{- else if and $isPostSelf (eq ($currentNode.Scratch.Get "relearnNextPage") nil) }}
|
||||
{{- $currentNode.Scratch.Set "relearnNextPage" .node }}
|
||||
{{- end}}
|
||||
{{- end }}
|
||||
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" .node.Pages }}
|
||||
{{- if .node.IsHome}}
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" .node.Sections }}
|
||||
{{- else if .node.Sections}}
|
||||
{{- $currentNode.Scratch.Set "relearnSubPages" (.node.Pages | union .node.Sections) }}
|
||||
{{- end}}
|
||||
{{- $pages := ($currentNode.Scratch.Get "relearnSubPages") }}
|
||||
|
||||
{{- if eq .Site.Params.ordersectionsby "title"}}
|
||||
{{- range $pages.ByTitle }}
|
||||
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current }}
|
||||
{{- end}}
|
||||
{{- else}}
|
||||
{{- range $pages.ByWeight }}
|
||||
{{- template "relearn-structure" dict "node" . "currentnode" $currentNode "hiddenstem" $hidden_stem "hiddencurrent" $hidden_from_current }}
|
||||
{{- end}}
|
||||
{{- end }}
|
||||
{{- end }}
|
Loading…
Reference in a new issue