-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render draft content, but do not publish it
After [discussing how to render drafts post][1], I wasn't satisfied by this solution: ``` --- # front-matter _build: list: never --- ``` While it did prevent draft content from appearing in other lists (rss, sitemap, taxonomies, etc.), I couldn't list them anymore in a specific path to retrieve them easily. So instead I chose a custom approach, I moved the draft content in a content/draft section, and moved draft posts in this section. Currently in order to avoid the modification of taxonomy pages like tags or series, these are commented in the front-matter of the posts pages (that may change in the future). Draft section wasn't displayed as expected, I needed to create a new default section layout, inspired by [section doc][4]. I had to modify the following default Hugo templates as well. * [RSS template][2] * [Sitemap template][3] And of course I needed to tweak the options of the hugo render in the Github Actions job. Finally I wanted to tweak the appearance of the body for draft blog post. Given the theme I chose, I needed to add specific [baseof layout for single page][5] [1]: https://discourse.gohugo.io/t/build-draft-or-future-posts-maybe-other-content-but-exclude-them-from-published-listings/25334/4 [2]: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/rss.xml [3]: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/_default/sitemap.xml [4]: https://gohugo.io/templates/section-templates/#example-creating-a-default-section-template [5]: https://gohugo.io/templates/lookup-order/
- Loading branch information
Showing
19 changed files
with
183 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
title: Drafts or ideas scratchpad | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{{- $pctx := . -}} | ||
{{- if .IsHome -}}{{ $pctx = .Site }}{{- end -}} | ||
{{- $pages := slice -}} | ||
{{- if or $.IsHome $.IsSection -}} | ||
{{- $pages = $pctx.RegularPages -}} | ||
{{- else -}} | ||
{{- $pages = $pctx.Pages -}} | ||
{{- end -}} | ||
{{- $limit := .Site.Config.Services.RSS.Limit -}} | ||
{{- if ge $limit 1 -}} | ||
{{- $pages = $pages | first $limit -}} | ||
{{- end -}} | ||
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }} | ||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | ||
<channel> | ||
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title> | ||
<link>{{ .Permalink }}</link> | ||
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description> | ||
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }} | ||
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }} | ||
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }} | ||
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }} | ||
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }} | ||
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }} | ||
{{ with .OutputFormats.Get "RSS" }} | ||
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }} | ||
{{ end }} | ||
{{ range $pages }} | ||
{{ if ne .Section "drafts" }} | ||
<item> | ||
<title>{{ .Title }}</title> | ||
<link>{{ .Permalink }}</link> | ||
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate> | ||
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}} | ||
<guid>{{ .Permalink }}</guid> | ||
<description>{{ .Summary | html }}</description> | ||
</item> | ||
{{ end }} | ||
{{ end }} | ||
</channel> | ||
</rss> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ define "header" }} | ||
{{ partial "header.html" . }} | ||
{{ end }} | ||
|
||
{{ define "content" }} | ||
{{ partial "page-list/content.html" . }} | ||
{{ end }} | ||
|
||
{{ define "footer" }} | ||
{{ partial "page-list/footer.html" . }} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="{{ .Site.LanguageCode }}"> | ||
{{ block "header" . }}{{ end }} | ||
<body class="{{if .Draft}}draft{{end}}"> | ||
{{ partial "sidebar.html" . }} | ||
<div class="content container"> | ||
{{ block "content" . }}{{ end }} | ||
</div> | ||
{{ block "footer" . }}{{ end }} | ||
</body> | ||
</html> | ||
{{/* More on template lookup : https://gohugo.io/templates/lookup-order/ */}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }} | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" | ||
xmlns:xhtml="http://www.w3.org/1999/xhtml"> | ||
{{ range .Data.Pages }} | ||
{{ if ne .Section "drafts" }} | ||
<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="{{ .Language.Lang }}" | ||
href="{{ .Permalink }}" | ||
/>{{ end }} | ||
<xhtml:link | ||
rel="alternate" | ||
hreflang="{{ .Language.Lang }}" | ||
href="{{ .Permalink }}" | ||
/>{{ end }} | ||
</url> | ||
{{ end }} | ||
{{ end }} | ||
</urlset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters