From e913aacb340d161c20f2e3e50e113e5d0e3df833 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sat, 26 Jan 2019 20:36:15 +0000 Subject: [PATCH] refactor: restructure config and front matter parameters - contact widget: support custom contact links with `contact_links` - talks: add `all_day` - custom_css/js -> plugins_css/js - load custom css/js from `assets/` dir instead of `static/` - minify custom css/js - convert publication types from config params to i18n translations - projects: always list child items (config option deprecated) BREAKING CHANGES: Refer to issue below. See #867 --- archetypes/talk/index.md | 1 + exampleSite/config/_default/params.toml | 174 +++++++++++----------- exampleSite/content/talk/example/index.md | 1 + i18n/en.yaml | 21 +++ layouts/partials/footer.html | 7 +- layouts/partials/header.html | 12 +- layouts/partials/pub_types.html | 1 + layouts/partials/talk_li_detailed.html | 2 +- layouts/partials/talk_li_simple.html | 2 +- layouts/partials/talk_li_stream.html | 2 +- layouts/partials/widgets/contact.html | 57 +++---- layouts/project/single.html | 81 +++++----- layouts/publication/single.html | 4 +- layouts/section/publication.html | 4 +- layouts/talk/single.html | 2 +- 15 files changed, 190 insertions(+), 181 deletions(-) create mode 100644 layouts/partials/pub_types.html diff --git a/archetypes/talk/index.md b/archetypes/talk/index.md index 27dba319..e8a65157 100644 --- a/archetypes/talk/index.md +++ b/archetypes/talk/index.md @@ -7,6 +7,7 @@ draft = false # End time can optionally be hidden by prefixing the line with `#`. time_start = {{ .Date }} time_end = {{ .Date }} +all_day = false # Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`. authors = [] diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index faa5f79b..c99a108a 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -24,123 +24,115 @@ twitter = "" # To enable, place an image in `static/img/` and reference its filename below. To disable, set the value to "". logo = "" -# Date and time format (refer to https://sourcethemes.com/academic/docs/customization/#date-format ) -# Examples: "Mon, Jan 2, 2006" or "2006-01-02" -date_format = "Jan 2, 2006" -# Examples: "3:04 pm" or "15:04" -time_format = "3:04 PM" - -# Show estimated reading time for posts? -reading_time = true - -# Display comment count? Requires commenting to be enabled. -comment_count = true - -# Display next/previous section pager? -section_pager = false - -# Enable global LaTeX math rendering? -# If false, you can enable it locally on a per page basis. -math = false - # Enable global source code highlighting? true/false # Documentation: https://sourcethemes.com/academic/docs/writing-markdown-latex/#highlighting-options highlight = true # highlight_languages = ["r"] # Add support for highlighting additional languages # highlight_style = "github" # For supported styles, see https://cdnjs.com/libraries/highlight.js/ -# Enable in-built social sharing buttons? -sharing = true +# Enable global LaTeX math rendering? +# If false, you can enable it locally on a per page basis. +math = false # Privacy pack # Show a cookie consent message to visitors # Anonymize IP in Google Analytics (if enabled) privacy_pack = false +# Date and time format (refer to https://sourcethemes.com/academic/docs/customization/#date-format ) +# Examples: "Mon, Jan 2, 2006" or "2006-01-02" +date_format = "Jan 2, 2006" +# Examples: "3:04 pm" or "15:04" +time_format = "3:04 PM" + +############################ +## Contact Widget setup ## +############################ + +# Enter contact details (optional). To hide a field, clear it to "". +email = "test@example.org" +phone = "888 888 88 88" +address = "Building 1 Room 1, Stanford University, California, 90210, USA" + +# Office hours: use `
` to insert a line break, or set to "" to remove office hours +office_hours = """Monday 10:00 to 13:00
+ Wednesday 09:00 to 10:00
+ Otherwise email to book an appointment""" + +# Enter an optional link for booking appointments (e.g. calendly.com). +appointment_url = "" + +# Contact links +# Set to `[]` to disable, or comment out unwanted lines with a hash `#`. +contact_links = [ + {icon = "twitter", icon_pack = "fab", name = "DM Me", link = "https://twitter.com/Twitter"}, + {icon = "skype", icon_pack = "fab", name = "Skype Me", link = "skype:echo123?call"}, + {icon = "keybase", icon_pack = "fab", name = "Chat on Keybase", link = "https://keybase.io/"}, + {icon = "comments", icon_pack = "fas", name = "Discuss on Forum", link = "https://discourse.gohugo.io"}, + # {icon = "telegram", icon_pack = "fab", name = "Telegram Me", link = "https://telegram.me/@Telegram"}, + ] + +# Display a map. +# To show your address on a map in the contact widget, you need to enter your latitude, longitude and choose +# a map provider below. +# To use Google Maps, set `map = 1` and enter your API key that can be obtained here: +# https://developers.google.com/maps/documentation/javascript/get-api-key +# To use OpenStreetMap tiles, set `map = 2`. +# To use OpenStreetMap on a high traffic site, set `map = 3` and enter your API key that can be obtained here: +# https://www.mapbox.com/studio/account/tokens +# To get your coordinates, right-click on Google Maps and choose "What's here?". The coords will show up at the bottom. +# +# Map provider: +# 0: No map +# 1: Google Maps +# 2: OpenStreetMap (Mapnik) +# 3: OpenStreetMap (Mapbox) +map = 0 +map_api_key = "" +latitude = "37.4275" +longitude = "-122.1697" +zoom = 15 + +############################ +## Plugins ## +############################ + +# Load CSS and JS plugins +# E.g. To load `/assets/css/custom.css`, set `plugins_css = ["custom"]`. +# E.g. To load `/assets/js/custom.js`, set `plugins_js = ["custom"]`. +plugins_css = [] +plugins_js = [] + +############################ +## Advanced options ## +############################ + # Get user avatars from Gravatar.com? (true/false) gravatar = false -# Contact Widget setup - email = "test@example.org" - address = "Building 1 Room 1, Stanford University, California, 90210, USA" - # Office hours: use `
` to insert a line break, or set to "" to remove office hours - office_hours = """Monday 10:00 to 13:00
- Wednesday 09:00 to 10:00
- Otherwise email to book an appointment""" - phone = "888 888 88 88" - skype = "echo123" - telegram = "" - keybase = "" # Your keybase.io username. - - # Enter an optional link for booking appointments (e.g. calendly.com). - appointment_url = "" - - # Discussion link (e.g. link to a forum, mailing list, or chat). - # Uncomment line below to use. - # discussion = { name = "Discuss", url = "https://discourse.gohugo.io" } - - # Enable/disable map in Contact widget. - # To show your address on a map in the contact widget, you need to enter your latitude, longitude and choose - # a map provider below. - # To use Google Maps, set `map = 1` and enter your API key that can be obtained here: - # https://developers.google.com/maps/documentation/javascript/get-api-key - # To use OpenStreetMap tiles, set `map = 2`. - # To use OpenStreetMap on a high traffic site, set `map = 3` and enter your API key that can be obtained here: - # https://www.mapbox.com/studio/account/tokens - # To get your coordinates, right-click on Google Maps and choose "What's here?". The coords will show up at the bottom. - # - # Map provider: - # 0: No map - # 1: Google Maps - # 2: OpenStreetMap (Mapnik) - # 3: OpenStreetMap (Mapbox) - map = 0 - map_api_key = "" - latitude = "37.4275" - longitude = "-122.1697" - zoom = 15 - -# Publication types. -# Used to categorize publications. -# The index of the publication type in the list is used as its unique numerical identifier. -# The numeric ID is used in a publication's frontmatter to categorize it. -# The language can be edited below. -# For multilingual sites, `publication_types` can be copied to each language section at the end of this file and -# translated. -publication_types = [ - 'Uncategorized', # 0 - 'Conference paper', # 1 - 'Journal article', # 2 - 'Manuscript', # 3 - 'Report', # 4 - 'Book', # 5 - 'Book section' # 6 -] - # Align the main menu to the right of the page? (true/false) menu_align_right = false -# Link custom CSS and JS assets -# (relative to /static/css and /static/js respectively) -custom_css = [] -custom_js = [] +# Show estimated reading time for posts? (true/false) +reading_time = true -# Configuration of talk pages. -[talks] - # Show talk time? - time = true +# Display comment count (if commenting enabled in config.toml)? (true/false) +comment_count = true + +# Display next/previous section pager? (true/false) +section_pager = false + +# Enable in-built social sharing buttons? (true/false) +sharing = true # Configuration of publication pages. [publications] # Date format (refer to https://sourcethemes.com/academic/docs/customization/#date-format ) # Examples: "Mon, Jan 2, 2006" or "2006-01-02" - date_format = "January, 2006" + date_format = "January 2006" # Configuration of project pages. [projects] - # List publications and talks related to the project? - list_children = true - # Post list format. # 0 = Simple # 1 = Detailed @@ -165,7 +157,7 @@ custom_js = [] [search] # Search provider: # 0: No search engine - # 1: Built-in (Fuse) + # 1: Academic (built-in) # 2: Algolia (https://www.algolia.com) engine = 1 diff --git a/exampleSite/content/talk/example/index.md b/exampleSite/content/talk/example/index.md index 2e081ec3..f263197b 100644 --- a/exampleSite/content/talk/example/index.md +++ b/exampleSite/content/talk/example/index.md @@ -7,6 +7,7 @@ draft = false # End time can optionally be hidden by prefixing the line with `#`. time_start = 2030-06-01T13:00:00 time_end = 2030-06-01T15:00:00 +all_day = false # Authors. Comma separated list, e.g. `["Bob Smith", "David Jones"]`. authors = [] diff --git a/i18n/en.yaml b/i18n/en.yaml index 8b78b7ab..37cb2097 100644 --- a/i18n/en.yaml +++ b/i18n/en.yaml @@ -143,6 +143,27 @@ - id: location translation: Location +- id: pub_uncat + translation: Uncategorized + +- id: pub_conf + translation: Conference paper + +- id: pub_journal + translation: Journal article + +- id: pub_manuscript + translation: Manuscript + +- id: pub_report + translation: Report + +- id: pub_book + translation: Book + +- id: pub_book_section + translation: Book section + # Filtering - id: filter_by_type diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 34895f9b..095d9257 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -140,13 +140,12 @@ {{ else }} {{ $js_bundle = slice $js_academic }} {{ end }} + {{ range .Site.Params.plugins_js }} + {{ $js_bundle = $js_bundle | append (resources.Get (printf "js/%s.js" .)) }} + {{ end }} {{ $js_bundle := $js_bundle | resources.Concat "js/academic-bundle-pre.js" | minify }} {{ $js_bundle := slice $js_bundle_head $js_bundle | resources.Concat "js/academic.min.js" | fingerprint "md5" }} - {{ range .Site.Params.custom_js }} - - {{ end }} - diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 340a36c9..684fcaa3 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -101,8 +101,16 @@ {{ end }} - {{ range .Site.Params.custom_css }} - + {{ if .Site.Params.plugins_css }} + {{ $css_comment := printf "/* Source Themes Academic v%s | https://sourcethemes.com/academic/ */\n" .Site.Data.academic.version }} + {{ $css_bundle_head := $css_comment | resources.FromString "css/bundle-head.css" }} + {{ $css_bundle := slice }} + {{ range .Site.Params.plugins_css }} + {{ $css_bundle = $css_bundle | append (resources.Get (printf "css/%s.css" .)) }} + {{ end }} + {{ $css_bundle := $css_bundle | resources.Concat "css/academic-bundle-pre.css" | minify }} + {{ $css_bundle := slice $css_bundle_head $css_bundle | resources.Concat "css/academic.css" | fingerprint "md5" }} + {{ end }} {{ if not .Site.IsServer }} diff --git a/layouts/partials/pub_types.html b/layouts/partials/pub_types.html new file mode 100644 index 00000000..896736cc --- /dev/null +++ b/layouts/partials/pub_types.html @@ -0,0 +1 @@ +{{ $.Scratch.Set "pub_types" (slice (i18n "pub_uncat" | default "Uncategorized") (i18n "pub_conf" | default "Conference paper") (i18n "pub_journal" | default "Journal article") (i18n "pub_manuscript" | default "Manuscript") (i18n "pub_report" | default "Report") (i18n "pub_book" | default "Book") (i18n "pub_book_section" | default "Book section") ) }} diff --git a/layouts/partials/talk_li_detailed.html b/layouts/partials/talk_li_detailed.html index 10a5149f..f87c8b90 100644 --- a/layouts/partials/talk_li_detailed.html +++ b/layouts/partials/talk_li_detailed.html @@ -18,7 +18,7 @@
{{ $date := .Params.time_start | default .Date }} {{ (time $date).Format $.Site.Params.date_format }} - {{ if $.Site.Params.talks.time }} + {{ if not .Params.all_day }} {{ (time $date).Format ($.Site.Params.time_format | default "3:04 PM") }} {{ with .Params.time_end }} — {{ (time .).Format ($.Site.Params.time_format | default "3:04 PM") }} diff --git a/layouts/partials/talk_li_simple.html b/layouts/partials/talk_li_simple.html index a562067e..e04e49f7 100644 --- a/layouts/partials/talk_li_simple.html +++ b/layouts/partials/talk_li_simple.html @@ -4,7 +4,7 @@
{{ $date := .Params.time_start | default .Date }} {{ (time $date).Format $.Site.Params.date_format }} - {{ if $.Site.Params.talks.time }} + {{ if not .Params.all_day }} {{ (time $date).Format ($.Site.Params.time_format | default "3:04 PM") }} {{ end }}
diff --git a/layouts/partials/talk_li_stream.html b/layouts/partials/talk_li_stream.html index fed3fb4b..3d836a05 100644 --- a/layouts/partials/talk_li_stream.html +++ b/layouts/partials/talk_li_stream.html @@ -23,7 +23,7 @@
{{ $date := .Params.time_start | default .Date }} {{ (time $date).Format $.Site.Params.date_format }} - {{ if $.Site.Params.talks.time }} + {{ if not .Params.all_day }} {{ (time $date).Format ($.Site.Params.time_format | default "3:04 PM") }} {{ with .Params.time_end }} — {{ (time .).Format ($.Site.Params.time_format | default "3:04 PM") }} diff --git a/layouts/partials/widgets/contact.html b/layouts/partials/widgets/contact.html index ea334d0a..18526105 100644 --- a/layouts/partials/widgets/contact.html +++ b/layouts/partials/widgets/contact.html @@ -53,24 +53,6 @@ {{ end }} - {{ with $.Site.Params.discussion }} -
  • - - - {{ .name }} - -
  • - {{ end }} - - {{ with $.Site.Params.keybase }} -
  • - - - @{{ . }} on Keybase. - -
  • - {{ end }} - {{ with $.Site.Params.phone }}
  • @@ -80,24 +62,6 @@
  • {{ end }} - {{ with $.Site.Params.skype }} -
  • - - - {{- if $autolink }}{{ . }}{{ else }}{{ . }}{{ end -}} - -
  • - {{ end }} - - {{ with $.Site.Params.telegram }} -
  • - - - {{- if $autolink }}@{{ . }}{{ else }}@{{ . }}{{ end -}} - -
  • - {{ end }} - {{ with $.Site.Params.address }}
  • @@ -119,6 +83,27 @@
  • {{ end }} + {{/* Contact links. */}} + {{ range $.Site.Params.contact_links }} + {{ $pack := or .icon_pack "fas" }} + {{ $pack_prefix := $pack }} + {{ if in (slice "fab" "fas" "far" "fal") $pack }} + {{ $pack_prefix = "fa" }} + {{ end }} + {{ $link := .link }} + {{ $scheme := (urls.Parse $link).Scheme }} + {{ $target := "" }} + {{ if not $scheme }} + {{ $link = .link | relLangURL }} + {{ else if in (slice "http" "https") $scheme }} + {{ $target = "target=\"_blank\" rel=\"noopener\"" }} + {{ end }} +
  • + + {{.name|markdownify|emojify|safeHTML}} +
  • + {{ end }} + {{ if $.Site.Params.map }} diff --git a/layouts/project/single.html b/layouts/project/single.html index fb5d3b28..7a1b7cf8 100644 --- a/layouts/project/single.html +++ b/layouts/project/single.html @@ -17,54 +17,51 @@ {{ $page := . }} {{ $project := .File.ContentBaseName }} - {{ if (.Site.Params.projects.list_children | default true) }} - - {{ $items := where (where .Site.RegularPages "Type" "post") ".Params.projects" "intersect" (slice $project) }} - {{ $count := len $items }} - {{ if ge $count 1 }} -

    {{ (i18n "posts") }}

    - {{ range $items }} - {{ if eq $page.Site.Params.projects.post_format 0 }} - {{ partial "post_li_simple" . }} - {{ else if eq $page.Site.Params.projects.post_format 1 }} - {{ partial "post_li_detailed" . }} - {{ else }} - {{ partial "post_li_stream" . }} - {{ end }} + {{ $items := where (where .Site.RegularPages "Type" "post") ".Params.projects" "intersect" (slice $project) }} + {{ $count := len $items }} + {{ if ge $count 1 }} +

    {{ (i18n "posts") }}

    + {{ range $items }} + {{ if eq $page.Site.Params.projects.post_format 0 }} + {{ partial "post_li_simple" . }} + {{ else if eq $page.Site.Params.projects.post_format 1 }} + {{ partial "post_li_detailed" . }} + {{ else }} + {{ partial "post_li_stream" . }} {{ end }} {{ end }} + {{ end }} - {{ $items := where (where .Site.RegularPages "Type" "publication") ".Params.projects" "intersect" (slice $project) }} - {{ $pubs_len := len $items }} - {{ if ge $pubs_len 1 }} -

    {{ (i18n "publications") }}

    - {{ range $items }} - {{ if eq $page.Site.Params.projects.publication_format 1 }} - {{ partial "publication_li_detailed" . }} - {{ else if eq $page.Site.Params.projects.publication_format 2 }} - {{ partial "publication_li_apa" . }} - {{ else if eq $page.Site.Params.projects.publication_format 3 }} - {{ partial "publication_li_mla" . }} - {{ else if eq $page.Site.Params.projects.publication_format 4 }} - {{ partial "publication_li_stream" . }} - {{ else }} - {{ partial "publication_li_simple" . }} - {{ end }} + {{ $items := where (where .Site.RegularPages "Type" "publication") ".Params.projects" "intersect" (slice $project) }} + {{ $pubs_len := len $items }} + {{ if ge $pubs_len 1 }} +

    {{ (i18n "publications") }}

    + {{ range $items }} + {{ if eq $page.Site.Params.projects.publication_format 1 }} + {{ partial "publication_li_detailed" . }} + {{ else if eq $page.Site.Params.projects.publication_format 2 }} + {{ partial "publication_li_apa" . }} + {{ else if eq $page.Site.Params.projects.publication_format 3 }} + {{ partial "publication_li_mla" . }} + {{ else if eq $page.Site.Params.projects.publication_format 4 }} + {{ partial "publication_li_stream" . }} + {{ else }} + {{ partial "publication_li_simple" . }} {{ end }} {{ end }} + {{ end }} - {{ $items := where (where .Site.RegularPages "Type" "talk") ".Params.projects" "intersect" (slice $project) }} - {{ $talks_len := len $items }} - {{ if ge $talks_len 1 }} -

    {{ (i18n "talks") }}

    - {{ range sort $items ".Params.time_start" "desc" }} - {{ if eq $page.Site.Params.projects.talk_format 1 }} - {{ partial "talk_li_detailed" . }} - {{ else if eq $page.Site.Params.projects.talk_format 2 }} - {{ partial "talk_li_stream" . }} - {{ else }} - {{ partial "talk_li_simple" . }} - {{ end }} + {{ $items := where (where .Site.RegularPages "Type" "talk") ".Params.projects" "intersect" (slice $project) }} + {{ $talks_len := len $items }} + {{ if ge $talks_len 1 }} +

    {{ (i18n "talks") }}

    + {{ range sort $items ".Params.time_start" "desc" }} + {{ if eq $page.Site.Params.projects.talk_format 1 }} + {{ partial "talk_li_detailed" . }} + {{ else if eq $page.Site.Params.projects.talk_format 2 }} + {{ partial "talk_li_stream" . }} + {{ else }} + {{ partial "talk_li_simple" . }} {{ end }} {{ end }} {{ end }} diff --git a/layouts/publication/single.html b/layouts/publication/single.html index 959c3d07..7577a9c4 100644 --- a/layouts/publication/single.html +++ b/layouts/publication/single.html @@ -18,9 +18,11 @@
    {{ i18n "publication_type" }}
    + {{ partial "pub_types.html" $ }} + {{ $pub_types := $.Scratch.Get "pub_types" }} {{ range $index, $pubtype := .Params.publication_types }} - {{ index $.Site.Params.publication_types (int .) }} + {{ index $pub_types (int .) }} {{ end }}
    diff --git a/layouts/section/publication.html b/layouts/section/publication.html index 45b130a9..602388ae 100644 --- a/layouts/section/publication.html +++ b/layouts/section/publication.html @@ -24,9 +24,11 @@
    diff --git a/layouts/talk/single.html b/layouts/talk/single.html index dc284626..ee3a7c35 100644 --- a/layouts/talk/single.html +++ b/layouts/talk/single.html @@ -22,7 +22,7 @@ {{ $date := .Params.time_start | default .Date }} {{ (time $date).Format $.Site.Params.date_format }}
    - {{ if $.Site.Params.talks.time }} + {{ if not .Params.all_day }} {{ (time $date).Format ($.Site.Params.time_format | default "3:04 PM") }} {{ with .Params.time_end }} — {{ (time .).Format ($.Site.Params.time_format | default "3:04 PM") }}