Skip to content

Commit

Permalink
Add page_info config and fix locale
Browse files Browse the repository at this point in the history
  • Loading branch information
salif committed Oct 31, 2024
1 parent 5b2e0db commit c287b01
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 78 deletions.
68 changes: 27 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,6 @@ npm run switch-to-latest

## Usage

### Front matter

| `extra.open_graph` keys | type | example | comment |
| --- | --- | --- | --- |
| `cover_type` | string | `image/jpeg`, `image/gif`, `image/png` | MIME type of the cover image |
| `cover_width` | string | | Width of the cover image in pixels |
| `cover_height` | string | | Height of the cover image in pixels |
| `expiration_time` | string | `"2024-02-29"` | When the article is out of date after |
| `content_tier` | string | `"free"`, `"locked"`, or `"metered"` | Describes the tier status for an article |
| `locations` | array of strings | `["county:COUNTY"]` or `["city:CITY,COUNTY"]` | Defines the location to target for the article |
| `section` | string | | A high-level section name. E.g. Technology |
| `tags` | array of strings | | Tag words associated with this article. |
| `opinion` | string | `"true"` or `"false"` | Indicates whether the article is an opinion piece or not |
| `audio` | string | | The URL for the audio |
| `audio_type` | string | `audio/vnd.facebook.bridge`, `audio/mpeg` | MIME type of the audio |
| `video` | string | | The URL for the video |
| `video_type` | string | `application/x-shockwave-flash`, `video/mp4` | MIME type of the video |
| `video_width` | string | | Width of the video in pixels |
| `video_height` | string | | Height of the video in pixels |
| `url` | string | | Set only if different from canonical page URL |

### TOML front matter

```toml
Expand All @@ -125,7 +104,6 @@ authors = []
# comment = true
# math = true
# mermaid = true
# show_updated_date = false
[extra.cover]
# image = ""
# alt = ""
Expand All @@ -149,14 +127,34 @@ extra:
comment: false
math: false
mermaid: false
show_updated_date: true
cover:
image: ""
alt: ""
open_graph:
---
```

### `extra.open_graph` keys

| key | type | example | comment |
| --- | --- | --- | --- |
| `cover_type` | string | `image/jpeg`, `image/gif`, `image/png` | MIME type of the cover image |
| `cover_width` | string | | Width of the cover image in pixels |
| `cover_height` | string | | Height of the cover image in pixels |
| `expiration_time` | string | `"2024-02-29"` | When the article is out of date after |
| `content_tier` | string | `"free"`, `"locked"`, or `"metered"` | Describes the tier status for an article |
| `locations` | array of strings | `["county:COUNTY"]` or `["city:CITY,COUNTY"]` | Defines the location to target for the article |
| `section` | string | | A high-level section name. E.g. Technology |
| `tags` | array of strings | | Tag words associated with this article. |
| `opinion` | string | `"true"` or `"false"` | Indicates whether the article is an opinion piece or not |
| `audio` | string | | The URL for the audio |
| `audio_type` | string | `audio/vnd.facebook.bridge`, `audio/mpeg` | MIME type of the audio |
| `video` | string | | The URL for the video |
| `video_type` | string | `application/x-shockwave-flash`, `video/mp4` | MIME type of the video |
| `video_width` | string | | Width of the video in pixels |
| `video_height` | string | | Height of the video in pixels |
| `url` | string | | Set only if different from canonical page URL |

### Authors

#### Option 1: Using Taxonomies
Expand Down Expand Up @@ -215,7 +213,7 @@ You can easily use inject to add new features to your side without modifying the

To use inject, you need to add some HTML files to the `templates/injects` directory.

The available inject points are: `head`, `header_nav`, `body_start`, `body_end`, `page_start`, `page_end`, `footer`, `page_info`.
The available inject points are: `head`, `header_nav`, `body_start`, `body_end`, `page_start`, `page_end`, `footer`.

For example, to load a custom script, you can add a `templates/injects/head.html` file:

Expand Down Expand Up @@ -286,19 +284,21 @@ paginate_by = 5

### `extra`

Strings in `extra.page_info` that are not one of the following, will be displayed directly in the UI:
`"date"`, `"date_updated"`, `"reading_time"`, `"word_count"`, `"authors"`.

| key | type | comment |
| --- | --- | --- |
| `extra.math` | boolean | Enable KaTeX math formula support globally |
| `extra.mermaid` | boolean | Enable Mermaid support globally |
| `extra.comment` | boolean | Enable comment support globally |
| `extra.show_updated_date` | boolean | Show the last updated date of posts |
| `extra.title_separator` | boolean | Title Separator |
| `extra.page_info` | array of strings | |
| `extra.style` | table | The theme style config |
| `extra.profiles` | table | Profiles |
| `extra.menu` | array of tables | The top menu |
| `extra.footer` | table | The page footer options |
| `extra.locales` | table | Locale codes and date formats |
| `extra.reading_time` | table | Word count and reading time for posts |
| `extra.goatcounter` | table | Enable web analytics |
| `extra.giscus` | table | The giscus comment options |

Expand All @@ -307,8 +307,8 @@ paginate_by = 5
math = false
mermaid = false
comment = false
show_updated_date = true
title_separator = " | "
page_info = ["date", "date_updated", "reading_time", "word_count", "authors"]
```

### The theme style config (`extra.style`)
Expand Down Expand Up @@ -519,20 +519,6 @@ date_format = "%x"
date_format_archive = "%m-%d"
```

### Reading time (`extra.reading_time`)

Possible values are `[]`, `["reading_time"]`, `["word_count"]`, `["reading_time", "word_count"]`, `["word_count", "reading_time"]`.

| key | type |
| --- | --- |
| `extra.reading_time[lang]` | array of strings |

```toml
[extra.reading_time]
en = ["reading_time"]
# fr = ["reading_time", "word_count"]
```

### Web analytics (`extra.goatcounter`)

Set only if you use [GoatCounter](https://www.goatcounter.com/).
Expand Down
6 changes: 0 additions & 6 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ error_404 = "404"
math = false
mermaid = false
comment = false
show_updated_date = true
title_separator = " | "

[extra.style]
Expand Down Expand Up @@ -262,11 +261,6 @@ locale = "eo"
date_format = "%d %b %Y"
date_format_archive = "%d %b"

[extra.reading_time]
en = ["reading_time"]
bg = ["reading_time"]
eo = ["word_count"]

[extra.goatcounter]
endpoint = "https://sgi.goatcounter.com/count"
src = "//gc.zgo.at/count.js"
Expand Down
4 changes: 2 additions & 2 deletions templates/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@
{%- if page.translations or section.translations %}
{%- set page_translations = page.translations | default(value=section.translations) %}
{%- for og_locale_alt in page_translations %}
{%- if og_locale_alt.lang == lang %}
{%- if og_locale_alt.lang == lang and config.extra.locales[lang].locale %}
<meta property="og:locale" content="{{ config.extra.locales[lang].locale }}" />
{%- elif config.extra.locales[og_locale_alt.lang].locale %}
{%- elif config.extra.locales[og_locale_alt.lang].locale and config.extra.locales[og_locale_alt.lang].locale %}
<meta property="og:locale:alternate" content="{{ config.extra.locales[og_locale_alt.lang].locale }}" />
{%- endif %}
<link rel="alternate" hreflang="{{ og_locale_alt.lang }}" href="{{ og_locale_alt.permalink | safe }}" />
Expand Down
60 changes: 31 additions & 29 deletions templates/partials/page_info.html
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
<div class="text-sm antialiased opacity-80">
{%- if page.date -%}
{%- set date_format = config.extra.locales[lang].date_format | default(value="%F") -%}
{%- if page.extra.show_updated_date is defined %}
{%- set show_updated_date = page.extra.show_updated_date %}
{%- elif config.extra.show_updated_date is defined %}
{%- set show_updated_date = config.extra.show_updated_date %}
{%- endif %}
{%- if page.extra.page_info %}
{%- set page_info = page.extra.page_info %}
{%- elif config.extra.page_info %}
{%- set page_info = config.extra.page_info %}
{%- else %}
{%- set page_info = ["date", "date_updated", "reading_time", "word_count", "authors"] %}
{% endif %}
{%- set date_format = config.extra.locales[lang].date_format | default(value="%F") %}
{%- for page_info_entry in page_info %}
{%- if page_info_entry == "date" %}
{%- if page.date %}
<time datetime="{{ page.date }}">{% if config.extra.locales[lang].locale %}{{
page.date | date(format=date_format, locale=config.extra.locales[lang].locale) }}{% else %}{{
page.date | date(format=date_format) }}{% endif %}</time>
{%- if show_updated_date and page.updated and page.updated != page.date -%}
{%- endif %}
{%- elif page_info_entry == "date_updated" %}
{%- if page.updated and page.updated != page.date -%}
&comma; <time datetime="{{ page.updated }}">{% if config.extra.locales[lang].locale %}{{
page.updated | date(format=date_format, locale=config.extra.locales[lang].locale) }}{% else %}{{
page.updated | date(format=date_format) }}{% endif %}</time>
{%- endif %}
{%- endif %}
{%- if config.extra.reading_time[lang] %}
{%- for reading_time in config.extra.reading_time[lang] %}
{%- elif page_info_entry == "reading_time" %}
<span class="mx-1">&middot;</span>
{%- if reading_time == "reading_time" %}
{%- set reading_time_minutes = page.reading_time % 60 %}
<time datetime="PT{{ (page.reading_time - reading_time_minutes) / 60 }}H{{ reading_time_minutes }}M0S">{{
page.reading_time }} {{ trans(key="word_minutes", lang=lang) }}</time>
{%- elif reading_time == "word_count" %}
{%- elif page_info_entry == "word_count" %}
<span class="mx-1">&middot;</span>
<span>{{ page.word_count }} {{ trans(key="word_words", lang=lang) }}</span>
{%- elif page_info_entry == "authors" %}
{%- if page.taxonomies.authors %}
{%- set page_authors = page.taxonomies.authors %}
{%- elif page.authors %}
{%- set page_authors = page.authors %}
{%- elif config.author %}
{%- set page_authors = [config.author] %}
{%- else %}
<span>{{ reading_time }}</span>
{%- set page_authors = [] %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- if page.taxonomies.authors %}
{%- set page_authors = page.taxonomies.authors %}
{%- elif page.authors %}
{%- set page_authors = page.authors %}
{%- elif config.author %}
{%- set page_authors = [config.author] %}
{%- else %}
{%- set page_authors = [] %}
{%- endif %}
{%- for page_author in page_authors %}
{%- for page_author in page_authors %}
<span class="mx-1">&middot;</span>
<span>{{ macros::get_profile_name(username=page_author) }}</span>
{%- endfor %}
<!-- Page Info inject -->
{% include "injects/page_info.html" ignore missing %}
{%- endfor %}
{%- else %}
{{ page_info_entry }}
{%- endif %}
{%- endfor %}
</div>

0 comments on commit c287b01

Please sign in to comment.