Skip to content

Commit

Permalink
Use filename as fallback for date
Browse files Browse the repository at this point in the history
Why:

 * when migrating from systems like jekylla and awestruct to hugo
   you might have hundreds if not thousands of blog entries using the
   filename as a way to set the date and slug part of page.
   i.e. 2017-08-01-my-life-as-a-dog.md would have a date of 2017-08-01 and
   a url called my-life-as-a-dog.md.

This change addreses the need by:

 * introduce a setting called `useFilenameDateAsFallback` that defaults to true,
   which will derive date and slug from the filename.
 * fix bug where adjusting metadata defaults were ignored when page has no frontmatter
  • Loading branch information
maxandersen committed Aug 29, 2017
1 parent f3f32bf commit e9417dc
Show file tree
Hide file tree
Showing 258 changed files with 14,573 additions and 33 deletions.
8 changes: 2 additions & 6 deletions docs/content/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ disablePathToLower = false
enableEmoji = false
# Show a placeholder instead of the default value or an empty string if a translation is missing
enableMissingTranslationPlaceholders = false
# Regex to use for dates in filenames.
filenameDateFallbackPattern = "(?P<year>\\d{4})\\-(?P<month>\\d{2})\\-(?P<day>\\d{2})"
# Time format for custom dates in filenames. Only used with `useFilenameDateAsFallback` and must match `filenameDateFallbackPattern`
filenameDateFallbackFormat = "2006-01-02"
footnoteAnchorPrefix = ""
footnoteReturnLinkContents = ""
# google analytics tracking id
Expand Down Expand Up @@ -302,8 +298,8 @@ theme = ""
title = ""
# if true, use /filename.html instead of /filename/
uglyURLs = false
#if true, use dates in filenames e.g. 2017-01-31-mypostname.md
useFilenameDateAsFallback = false
# use dates in filenames e.g. 2017-01-31-mypostname.md
useFilenameDateAsFallback = true
# verbose output
verbose = false
# verbose logging
Expand Down
6 changes: 5 additions & 1 deletion docs/content/variables/page.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ See [`.Scratch`](/functions/scratch/) for page-scoped, writable variables.

`.Date`
: the date associated with the page; `.Date` pulls from the `date` field in a content's front matter.
If you're migrating content to Hugo, you may have content with dates in the filename. For example `2017-01-31-myblog.md`. You can optionally enable the `useFilenameDateAsFallback` configuration option. This will attempt to parse the datestamp in the filename and use it as a fallback to providing a date variable in the front matter.
If no `date` field present Hugo will try and extract the date from the filename. For example `2017-01-31-myblog.md`. It will also set `.Slug` to contain the path without the
date prefix.'

You can disable the automatic date detection and slug modification by setting `useFilenameDateAsFallback` configuration option to false.

See also `.ExpiryDate`, `.PublishDate`, and `.Lastmod`.

`.Description`
Expand Down
4 changes: 4 additions & 0 deletions docs/themes/gohugoioTheme/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src/node_modules
node_modules
.DS_Store
*.log
1 change: 1 addition & 0 deletions docs/themes/gohugoioTheme/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Theme for gohugo.io sites. More info to come.
13 changes: 13 additions & 0 deletions docs/themes/gohugoioTheme/archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
linktitle: ""
description: ""
godocref: ""
publishdate: ""
lastmod: ""
categories: []
tags: []
weight: 00
slug: ""
aliases: []
toc: false
---
17 changes: 17 additions & 0 deletions docs/themes/gohugoioTheme/archetypes/functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
linktitle: ""
description: ""
godocref: ""
publishdate: ""
lastmod: ""
categories: [functions]
tags: []
ns: ""
signature: []
workson: []
hugoversion: ""
aliases: []
relatedfuncs: []
toc: false
deprecated: false
---
13 changes: 13 additions & 0 deletions docs/themes/gohugoioTheme/archetypes/showcase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
description: ""
lastmod: ""
license: ""
licenseLink: ""
sitelink: ""
sourcelink: ""
categories: [showcase]
tags: []
image: ""
toc: false
notesforauthors: "Go to gohugo.io/contribute/documentation for more info"
---
16 changes: 16 additions & 0 deletions docs/themes/gohugoioTheme/archetypes/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
linktitle: ""
description: ""
godocref: ""
publishdate: ""
lastmod: ""
categories: [tutorials]
tags: []
author: ""
authorurl: ""
originalurl: ""
draft: false
aliases: []
notesforauthors: "Go to gohugo.io/contribute/documentation for more info."
---

10 changes: 10 additions & 0 deletions docs/themes/gohugoioTheme/layouts/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{ define "main" }}
<main class="cf pa5 pa4-l f4 tc center measure-wide lh-copy gray">
<h1 class="f3 f2-ns">The page you're looking for doesn't exist. Perhaps you'd like to gopher something else? Sorry.</h1>
<div class="h6">
{{ partial "svg/gopher-hero.svg" . }}
</div>

{{ .Content }}
</main>
{{ end }}
51 changes: 51 additions & 0 deletions docs/themes/gohugoioTheme/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html class="no-js" lang="{{ with $.Site.LanguageCode }}{{ . }}{{ else }}en-us{{ end }}">
<head>
<meta charset="utf-8">
{{/* https://www.zachleat.com/web/preload/ */}}
<link rel="preload" href="{{ "files/muli-latin-200.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="{{ "files/muli-latin-400.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="{{ "files/muli-latin-800.woff2" | absURL }}" as="font" type="font/woff2" crossorigin>

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
{{/* NOTE: the Site's title, and if there is a page title, that is set too */}}
<title>{{ block "title" . }}{{ .Site.Title }} {{ with .Title }} | {{ . }}{{ end }}{{ end }}</title>
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">

<meta name="viewport" content="width=device-width,minimum-scale=1">
{{ .Hugo.Generator }}

{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }}
<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
{{ else }}
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
{{ end }}

<link href='{{ "dist/main.css" | relURL }}' rel='stylesheet' type="text/css" />
{{- partial "head-additions.html" . -}}
{{- template "_internal/opengraph.html" . -}}
{{- template "_internal/google_news.html" . -}}
{{- template "_internal/schema.html" . -}}
{{- partial "twitter_cards.html" . -}}

{{ if eq (getenv "HUGO_ENV") "production" | or (eq .Site.Params.env "production") }}
{{ template "_internal/google_analytics_async.html" . }}
{{ end }}




</head>
<body class="ma0 sans-serif bg-primary-color-light{{ with getenv "HUGO_ENV" }} {{ . }}{{ end }}">
{{ block "nav" . }}{{ partial "site-nav.html" . }}{{ end }}
{{ block "header" . }}{{ end }}
<main role="main" class="content-with-sidebar min-vh-100 pb7 pb0-ns">
{{ block "main" . }}{{ end }}
</main>

{{ block "footer" . }}{{ partial "site-footer.html" . }}{{ end }}
{{ block "scripts" . }}{{- partial "site-scripts.html" . -}}{{ end }}

</body>
</html>
4 changes: 4 additions & 0 deletions docs/themes/gohugoioTheme/layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ define "main" }}
{{ $section_to_display := .Sections | default .Paginator.Pages }}
{{ partial "pagelayout.html" (dict "context" . "section_to_display" $section_to_display ) }}
{{ end }}
37 changes: 37 additions & 0 deletions docs/themes/gohugoioTheme/layouts/_default/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<header class="flex-none w-100">
{{ if .Params.categories }}
{{ range .Params.categories }}
<a href="{{ "/categories/" | relLangURL }}{{ . | urlize }}" class="f6 fw8 mb0 link mid-gray dim mr3">
{{ humanize . | upper }}
</a>
{{ end }}
{{end}}
<h1 class="lh-title mb3 mv0 pt3 primary-color-dark">
{{- if eq .Section "functions" -}}
{{ .LinkTitle }}
{{- else -}}
{{ .Title }}
{{- end -}}
</h1>
</header>

<aside class="bt bw1 pt3 mt2 mid-gray b--mid-gray fn w-100">
{{ with .Params.description }}
<div class="f4 fw4 lh-copy">
{{ . | markdownify }}
</div>
{{ end }}

<!--
NOTE: Removed to test builds without it.
partial "components/author-github-data" (dict "context" . "size" "110") -->
</aside>

{{ with .Params.featured_image_path }}
<img src="{{ . }}" alt="Featured Image for {{ $.Title }}" class="mw-100">
{{ end }}

<div class="prose" id="prose">
{{- partial "docs/functions-signature.html" . -}}
{{ .Content }}
</div>
30 changes: 30 additions & 0 deletions docs/themes/gohugoioTheme/layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ define "main" }}
<article class="w-100 ph4 pb5 pb6-ns pt1 pt5-ns">
<div class="flex-l">

<div class="order-2 w-100 w-20-l ph5-m ph0-l mb4 sticky">
{{- partial "toc.html" . -}}
</div>

<div class="order-1 w-60-l mw7 ph0 ph5-ns mid-gray nested-copy-line-height no-underline nested-links nested-img nested-copy-seperator nested-blockquote mt0-ns" style="flex-grow:1;">
<div class="documentation-copy center measure-wide-l">
<div id="readout" class="fixed right-0 bottom-0">
</div>
{{ .Render "page" }}
</div>
</div>
<div class="order-0 w-20 dn db-l">
{{ partial "nav-links-docs.html" . }}
</div>

</div>
</article>

<div class="w-100 bg-light-gray">
<div class="mw7 pa4 center nested-lh-copy lh-copy">
{{ partial "docs/page-meta-data.html" . }}
{{ partial "page-edit.html" . }}
{{ partial "tags.html" . }}
</div>
</div>
{{ end }}
4 changes: 4 additions & 0 deletions docs/themes/gohugoioTheme/layouts/_default/taxonomy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ define "main" }}
{{ $section_to_display := .Data.Pages }}
{{ partial "pagelayout.html" (dict "context" . "section_to_display" $section_to_display ) }}
{{ end }}
49 changes: 49 additions & 0 deletions docs/themes/gohugoioTheme/layouts/_default/terms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{{/* {{ define "header" }}{{ partial "page-header" . }}{{ end }} */}}
{{ define "main" }}
{{ $section_to_display := .Data.Pages }}
<div class="w-100 ph4 pb5 pb6-ns pt1 pt3-ns">

<div class="flex">
<div class="dn db-l w-20">
{{ partial "nav-links-docs.html" . }}
</div>

<div class="w-100 w-80-l ph0 ph4-l">
<article class="w-100 nested-copy-line-height nested-links nested-img">
<h1 class="primary-color-dark f2">
{{ .Title }}
</h1>
</article>
<div class="pa3 pa4-ns w-100 v-top column-count-3-l column-gap-1-l">
{{ range $key, $value := .Data.Terms }}
<div class="break-inside-avoid-l nested-copy-line-height mb5">
<h2 class="f3">
<a href="{{ "/" | relLangURL }}{{ $.Data.Plural | urlize }}/{{ $key | urlize }}" class="link black hover-blue">
{{ $key }} <span class="f6 gray"> &#8599;</span>
</a>
</h2>
{{ range $value.Pages }}
<h3>
<a href="{{ .Permalink }}" class="link blue">
{{ .Title }}
</a>
</h3>
{{ end }}
</div>

{{ end }}

</div>




</div>

</div>




</div>
{{ end }}
8 changes: 8 additions & 0 deletions docs/themes/gohugoioTheme/layouts/index.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Referrer-Policy: origin-when-cross-origin
*/
Link: <{{ "dist/app.bundle.js" | relURL }}>; rel=preload; as=script
Link: <{{ "dist/main.css" | relURL }}>; rel=preload; as=style
23 changes: 23 additions & 0 deletions docs/themes/gohugoioTheme/layouts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{ define "header" }}
{{ partial "hero" . }}
{{ partial "boxes-small-news" . }}
{{ end }}

{{ define "main" }}

<section class="w-100 ph4 ph5-ns pv4">
{{- partial "home-page-sections/features-icons" . -}}
</section>

{{- partial "home-page-sections/features-single" . -}}

<section class="w-100 ph4 ph5-ns pv4 pv6-ns mid-gray bg-white bb bt b--light-gray">
{{- partial "home-page-sections/installation" . -}}
</section>
<section class="w-100 ph4 ph5-ns pv4 pv6-ns mid-gray bg-accent-color-dark">
{{- partial "home-page-sections/tweets" . -}}
</section>
<section class="w-100 ph4 ph5-ns pt4 pb5 mid-gray bg-primary-color-light bb bt b--light-gray ">
{{- partial "home-page-sections/open-source-involvement" . -}}
</section>
{{ end }}
6 changes: 6 additions & 0 deletions docs/themes/gohugoioTheme/layouts/index.redir
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Netlify redirects. See https://www.netlify.com/docs/redirects/
{{ range $p := .Site.Pages -}}
{{ range .Aliases }}
{{ . | printf "%-35s" }} {{ $p.RelPermalink -}}
{{ end -}}
{{- end -}}
42 changes: 42 additions & 0 deletions docs/themes/gohugoioTheme/layouts/news/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{/* TODO: think about adding these tags back in, but they need to be limited to news
{{ define "header" }}{{ partial "page-header" . }}{{ end }} */}}
{{ define "main" }}
<div class="w-100 ph4 ph5-ns pb5 pb6-ns pt1 pt3-ns ">

<article class="cf pa3 pa4-m pa4-l nested-copy-line-height nested-img">
<h1 class="primary-color-dark">
{{ .Title }}
</h1>
<div class="nested-copy-line-height">
{{ .Content }}
</div>
</article>

<!-- TODO: May be a good idea in this case to add monthly archives -->

<div class="flex flex-wrap">
{{/* [wip] add archive lists
<div class="w-100 w-20-ns dn">
<ul>
<li>
<a href="#">
archive section
</a>
</li>
</ul>
</div> */}}

{{ $interior_classes := $.Site.Params.flex_box_interior_classes }}
<section class="flex-ns flex-wrap justify-between w-100 w-80-nsTK v-top">
{{ range .Paginator.Pages }}
{{ partial "boxes-section-summaries" (dict "context" . "classes" $interior_classes "fullcontent" false) }}
{{ end }}
</section>
</div>
<div class="nested-list-reset nested-links">
{{/* pagination.html: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/template_embedded.go#L117 */}}
{{ template "_internal/pagination.html" . }}
</div>

</div>
{{ end }}
Loading

0 comments on commit e9417dc

Please sign in to comment.