Skip to content

Commit

Permalink
Render draft content, but do not publish it
Browse files Browse the repository at this point in the history
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
bric3 committed May 13, 2020
1 parent 2280e72 commit 0df7126
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-pages-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 0

- name: Build
run: docker run --rm --volume $PWD:/src bric3/hugo-builder hugo
run: docker run --rm --volume $PWD:/src bric3/hugo-builder hugo --verbose --buildDrafts --buildFuture

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
Expand Down
15 changes: 15 additions & 0 deletions assets/scss/hyde-hyde-dark/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ body {
color: $dark-body-color;
}

body.draft {
background: repeating-linear-gradient(
45deg,
rgba(0, 0, 0, 0.5),
rgba(0, 0, 0, 0.5) 1rem,
rgba(0, 0, 0, 0.2) 1rem,
rgba(0, 0, 0, 0.2) 2rem
);
& > div.content.container::before {
color: $draft-red;
background: $dark-body-bg-color;
border-color: $draft-red;
}
}

blockquote {
color: $dark-quote-color;
background-color: $dark-blockquote-bg-color;
Expand Down
3 changes: 2 additions & 1 deletion assets/scss/hyde-hyde-dark/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
$draft-red: rgb(210, 42, 42);

$scrollbar-color: rgba(172, 133, 47, 0.4);
$link-color: rgb(240, 214, 167);
$link-hover-color: rgb(251, 224, 174);
$tag-color: rgb(113, 89, 68);
$navigation-color: rgb(113, 89, 68);

$dark-bg-color: #201e19;
$dark-bg-color: rgb(32, 30, 25);
$dark-body-color: rgba(255, 255, 226, 0.8);
$dark-body-bg-color: rgb(36, 32, 25);
$dark-text-color: rgb(255, 255, 218);
Expand Down
22 changes: 22 additions & 0 deletions assets/scss/hyde-hyde/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,25 @@ ul.posts {
}
}

body.draft {
background: repeating-linear-gradient(
45deg,
rgba(0, 0, 0, 0.1),
rgba(0, 0, 0, 0.1) 1rem,
rgba(0, 0, 0, 0.15) 1rem,
rgba(0, 0, 0, 0.15) 2rem
);
& > div.content.container::before {
content: "DRAFT";
color: $red;
margin-left: 80%;
position: -webkit-sticky;
position: sticky;
top: -3px;
z-index: 1000;
background: $body-bg;
border: $red solid 1px;
border-radius: 4px;
padding: 0.2rem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ authors: ["brice.dutheil"]
date: "2017-11-20T00:00:00Z"
language: en
published: false
tags:
- java
- jaxrs
- versionning
- http
- jersey
- resteasy
- vendoring
- vendor tree
- mediatype
- media type
# tags:
# - java
# - jaxrs
# - versionning
# - http
# - jersey
# - resteasy
# - vendoring
# - vendor tree
# - mediatype
# - media type
slug: API-versioning-with-JAX-RS
title: The Quest to API versioning with JAX-RS
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
authors: ["brice.dutheil"]
date: "2018-02-20T00:00:00Z"
language: en
published: false
tags:
- java
- jaxrs
- URL
- URI
- Retrofit
- OkHttp
- HttpUrl
- leading
- trailing
- opinion
#tags:
#- java
#- jaxrs
#- URL
#- URI
#- Retrofit
#- OkHttp
#- HttpUrl
#- leading
#- trailing
#- opinion
slug: URI_paths_with_trailing_or_leading_slashes
title: Opinion, should we prefix JAX-RS Path value with a slash ?
published: false
---

In the past months I have been using extensively the infamous HTTP client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
authors: ["brice.dutheil"]
date: "2018-05-04T00:00:00Z"
language: en
published: false
tags:
- java
- TCE
- tail call elimination
- recursion
#tags:
#- java
#- TCE
#- tail call elimination
#- recursion
slug: programmatic-tail-call-elimination-in-java
title: Programmatic tail call elimination in Java
published: false
---


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
authors: ["brice.dutheil"]
date: "2019-02-14T00:00:00Z"
language: en
published: false
tags:
- Java
- Jackson
- Json
- lombok
- immutable
slug: immutable-jackson-pojo-with-lombok
title: Immutable jackson pojo with Lombok
# tags: ["Java" ,"Jackson" ,"Json" ,"lombok" ,"immutable"]
published: false
---

## The quest to immutable objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
authors: ["brice.dutheil"]
date: "2019-09-13T00:00:00Z"
language: fr
published: false
tags:
- Java
- Linux
- docker
- kubernetes
- inotify
- WatchService
slug: watchservice-and-bind-mount.fr
title: Lorsque le WatchService de Java n'est pas le bon outil dans un conteneur
#tags: ["Java", "Linux", "docker", "kubernetes", "inotify", "WatchService"]
published: false
---

## Boring code that should be written once and run everywhere
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
authors: ["brice.dutheil"]
date: "2020-03-12T00:00:00Z"
language: en
published: false
tags: ["Java", "Corretto", "OpenJDK", "JDK"]
slug: hacking-the-jdk
title: Hacking the JDK
published: false
#tags: ["Java", "Corretto", "OpenJDK", "JDK"]
#_build:
# list: never
---

== How to build your corretto JDK
Expand Down Expand Up @@ -289,13 +291,13 @@ coretto-11/src❯ idea .

And voilà

image:/assets/corretto-11-in-intellij-idea.png[OpenJDK browsing in IntelliJ IDEA]
image:/assets/hacking-corretto-11/corretto-11-in-intellij-idea.png[OpenJDK browsing in IntelliJ IDEA]

One thing I noticed is that the project has been set for Java 9 language level,
but some Java code actually have language features from Java 10, like `var`.
So I had to increase the project language level.

image:/assets/corretto-11-project-source-level.png[corretto source project level]
image:/assets/hacking-corretto-11/corretto-11-project-source-level.png[corretto source project level]

== Let's play with the jdk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ authors: ["brice.dutheil"]
date: "2020-04-24T11:54:58+02:00"
language: en
draft: true
tags: ["jfr","profiling","java flight recorder", "java"]
#tags: ["jfr","profiling","java flight recorder", "java"]
slug: "using-java-flight-recorder"
title: "Using Java FlightRecorder"
#series: ["Flight Recorder"]
#_build:
# list: never
---


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
authors: ["brice.dutheil"]
date: "2020-04-27T11:45:29+02:00"
language: en
draft: true
tags: ["cgroup", "java", "kubernetes", "docker"]
#tags: ["cgroup", "java", "kubernetes", "docker"]
slug: "maxrampercentage-isnt-enough"
title: "MaxRamPercentage isn't enough"
draft: true
#_build:
# list: never
---

== App Docker image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ authors: ["brice.dutheil"]
date: "2020-04-29T15:15:09+02:00"
language: en
draft: true
tags: ["cool-tag"]
#tags: ["watchman", "watchexec", "watch"]
slug: "watchman"
title: "Watchman"
series: "Watching Files"
#series: "Watching Files"
#_build:
# list: never
---

**Insert Lead paragraph here.**
Expand Down
3 changes: 3 additions & 0 deletions content/drafts/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Drafts or ideas scratchpad
---
41 changes: 41 additions & 0 deletions layouts/_default/rss.xml
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>
11 changes: 11 additions & 0 deletions layouts/_default/section.html
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 }}
12 changes: 12 additions & 0 deletions layouts/_default/single-baseof.html
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/ */}}
24 changes: 24 additions & 0 deletions layouts/_default/sitemap.xml
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>
2 changes: 1 addition & 1 deletion serve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# slow but use the same build as used on Github Actions
#exec docker run --rm --volume $PWD:/src --publish "0.0.0.0:1313:1313" bric3/hugo-builder hugo serve --bind=0.0.0.0 --baseUrl=blog.local --buildDrafts

exec env PATH=$PWD/bin:$PATH hugo serve --baseUrl=blog.local --bind=0.0.0.0 --buildDrafts
exec env PATH=$PWD/bin:$PATH hugo serve --verbose --baseUrl=blog.local --bind=0.0.0.0 --buildDrafts --buildFuture

0 comments on commit 0df7126

Please sign in to comment.