feat: add support for giscus and utterances

main
welpo 2 years ago
parent 3e215e18e2
commit 5993e950c7
No known key found for this signature in database
GPG Key ID: A2F978CF4EC1F5A6

@ -16,18 +16,19 @@ tabi has a perfect score on Google's Lighthouse audit:
- [X] Multi-language support.
- [X] Dark and light themes. Defaults to the OS setting, with a switcher in the navigation bar.
- [X] Support for [comments using giscus or utterances](https://welpo.github.io/tabi/blog/comments/).
- [X] Perfect Lighthouse score (Performance, Accessibility, Best Practices and SEO).
- [X] [KaTeX](https://katex.org/) support.
- [X] All JavaScript (theme switcher and KaTeX) can be fully disabled.
- [X] Stylized [feed](https://welpo.github.io/tabi/atom.xml).
- [X] Responsive design.
- [X] Projects page.
- [X] Archive page.
- [X] All JavaScript can be [fully disabled](https://welpo.github.io/tabi/blog/javascript/).
- [X] [Stylized feed](https://welpo.github.io/tabi/atom.xml).
- [X] [Projects page](https://welpo.github.io/tabi/projects/).
- [X] [Archive page](https://welpo.github.io/tabi/archive/).
- [x] Tags.
- [x] Social links.
- [X] Responsive design.
- [X] Code syntax highlighting.
- [X] [Customizable secure headers](https://welpo.github.io/tabi/blog/security/).
- [X] [Custom shortcodes](https://welpo.github.io/tabi/blog/shortcodes/).
- [X] Customizable secure headers.
## Quick start

@ -68,6 +68,7 @@ table_of_contents = "Tabla de contenido"
last_updated_on = "Última actualización el"
show_original_quote = "Mostrar cita original"
show_translation = "Mostrar traducción"
load_comments = "Cargar comentarios"
# Quotation marks for multilingual quote shortcode.
open_quotation_mark = "«"
close_quotation_mark = "»"
@ -101,6 +102,7 @@ table_of_contents = "Taula de contingut"
last_updated_on = "Última actualizació el"
show_original_quote = "Mostra la cita original"
show_translation = "Mostra la traducció"
load_comments = "Carregar comentaris"
# Quotation marks for multilingual quote shortcode.
open_quotation_mark = "«"
close_quotation_mark = "»"
@ -179,28 +181,31 @@ allowed_domains = [
custom_subset = true
# giscus support for comments. https://giscus.app
# Setup instructions: https://welpo.github.io/tabi/blog/comments/#setup
[extra.giscus]
enabled_for_all_posts = false # Enables giscus on all posts. It can be enabled on individual posts by setting `giscus = true` in the [extra] section of the post's front matter.
repo = "welpo/test-utterances"
repo_id = "R_kgDOJ59Urw"
enabled_for_all_posts = false # Enables giscus on all posts. It can be enabled on individual posts by setting `giscus = true` in the [extra] section of a post's front matter.
automatic_loading = true # If set to false, a "Show comments" button will be shown.
repo = "welpo/tabi-comments"
repo_id = "R_kgDOJ59Urw" # Find this value in https://giscus.app/
category = "Announcements"
category_id = "DIC_kwDOJ59Ur84CX0QG"
category_id = "DIC_kwDOJ59Ur84CX0QG" # Find this value in https://giscus.app/
mapping = "slug" # Available: pathname; url; title; slug. "slug" will use the post's filename (slug); this is the only way to share comments between languages.
strict_title_matching = 1 # 1 to enable, 0 to disable. https://github.com/giscus/giscus/blob/main/ADVANCED-USAGE.md#data-strict
enable_reactions = 1 # 1 to enable, 0 to disable.
comment_box_above_comments = true
light_theme = "noborder_light"
dark_theme = "noborder_dark"
lang = "" # Leave blank to set it based on the page's language.
lang = "" # Leave blank to match the page's language.
lazy_loading = true
automatic_loading = true # If set to false, a "Show comments" button will be shown.
# utterances support for comments. https://utteranc.es
# Setup instructions: https://welpo.github.io/tabi/blog/comments/#setup
[extra.utterances]
enabled_for_all_posts = false # Enables utterances on all posts. It can be enabled on individual posts by setting `utterances = true` in the [extra] section of the post's front matter.
repo = "yourgithubuser/yourrepo" # https://utteranc.es/#heading-repository
enabled_for_all_posts = false # Enables utterances on all posts. It can be enabled on individual posts by setting `utterances = true` in the [extra] section of a post's front matter.
automatic_loading = true # If set to false, a "Show comments" button will be shown.
repo = "yourGithubUsername/yourRepo" # https://utteranc.es/#heading-repository
issue_term = "slug" # Available: pathname; url; title; slug. "slug" will use the post's filename (slug); this is the only way to share comments between languages. https://utteranc.es/#heading-mapping
label = "💬" # https://utteranc.es/#heading-issue-label
light_theme = "github-light" # https://utteranc.es/#heading-theme
dark_theme = "github-dark" # https://utteranc.es/#heading-theme
dark_theme = "photon-dark" # https://utteranc.es/#heading-theme
lazy_loading = true

@ -0,0 +1,93 @@
+++
title = "Afegeix comentaris a les teves publicacions amb giscus o utterances"
date = 2023-07-14
description = "Descobreix com habilitar una secció de comentaris a les teves publicacions utilitzant giscus o utterances, permetent la interacció i feedback dels lectors."
[taxonomies]
tags = ["funcionalitat", "tutorial"]
[extra]
giscus = true
+++
tabi actualment suporta dos sistemes de comentaris: [giscus](https://giscus.app/ca) i [utterances](https://utteranc.es/).
giscus i utterances són projectes de codi obert que et permeten afegir una secció de comentaris al teu lloc web utilitzant les «issues» (utterances) o «discussions» (giscus) de GitHub. Són perfectes per a generadors de llocs estàtics com Zola, ja que permeten als teus lectors interactuar i deixar comentaris a les teves publicacions sense requerir un backend tradicional o una base de dades.
Com que tots dos es basen en GitHub, giscus i utterances requereixen que els usuaris tinguin un compte a GitHub i autoritzin l'aplicació respectiva. Alternativament, els visitants també poden comentar directament en la discussió o «issue» corresponent a GitHub.
Ambdues són excel·lents eines per afegir comentaris al teu blog, però giscus té alguns avantatges:
- Més temes.
- Suport per a reaccions.
- Respostes a comentaris i vista de conversa.
- Més segur: utterances requereix habilitar estils en línia no segurs («unsafe inline styles») per establir l'altura del frame; giscus no.
- Suport multilingüe: utterances només està disponible en anglès; giscus suporta més de 20 idiomes.
- Desenvolupament més actiu: l'últim commit de giscus, en el moment d'aquesta publicació, va ser fa una setmana. L'últim commit d'utterances es va fer fa més d'un any.
## Configuració
Tots dos sistemes requereixen una configuració similar. Primer, visita el lloc web del sistema que vols habilitar: [giscus.app](https://giscus.app/ca) o [utteranc.es](https://utteranc.es/).
Segueix les instruccions de la secció **Configuració** del lloc web, i tria les opcions que prefereixis. Finalment, estableix els valors que es mostren a la secció **Habilitar giscus/utterances** (el bloc de codi `script`) en la secció corresponent del teu `config.toml`: `[extra.giscus]` o `[extra.utterances]`.
### Giscus
giscus té més opcions que utterances:
```toml
[extra.giscus]
enabled_for_all_posts = false
automatic_loading = true
repo = "elTeuNomDUsuariDeGithub/elTeuRepositori"
repo_id = "LaTevaIDdeRepositori"
category = "Anuncis"
category_id = "LaTevaIDdeCategoria"
mapping = "slug"
strict_title_matching = 1 # 1 per habilitar, 0 per deshabilitar.
enable_reactions = 1 # 1 per habilitar, 0 per deshabilitar.
comment_box_above_comments = true
light_theme = "noborder_light"
dark_theme = "noborder_dark"
lang = "" # Deixa en blanc perquè coincideixi amb l'idioma de la pàgina.
lazy_loading = true
```
### utterances
```
[extra.utterances]
enabled_for_all_posts = false
automatic_loading = true
repo = "elTeuNomDUsuariDeGithub/elTeuRepositori"
issue_term = "slug"
label = "💬"
light_theme = "github-light"
dark_theme = "photon-dark"
lazy_loading = true
```
### Configuracions comunes
La opció `enabled_for_all_posts = true` habilita globalment el sistema de comentaris corresponent.
Alternativament, pots habilitar els comentaris de publicacions concretes afegint `utterances = true` o `giscus = true`. Per exemple, així és com habilitaries giscus:
```toml,hl_lines=09-10
+++
title = "L'art de l'entremaliadura segons Shin-Chan
date = 1990-02-14
description = "Descobreix com les travessures poden canviar la teva perspectiva de vida."
[taxonomies]
tags = ["personal", "travessures"]
[extra]
giscus = true
+++
```
Si accidentalment habilitas tots dos sistemes, Zola mostrarà un error.
Si el teu lloc web té múltiples idiomes amb publicacions coincidents (com aquesta demo), i t'agradaria compartir comentaris entre idiomes, has d'utilitzar `issue_term = "slug"`. Això utilitzarà el nom de l'arxiu Markdown (sense l'etiqueta d'idioma) com a identificador. Totes les altres opcions crearan diferents seccions de comentaris per a cada idioma.
## Exemple en viu
A continuació trobaràs el widget de giscus amb la configuració mostrada [a dalt](#giscus).

@ -0,0 +1,96 @@
+++
title = "Añade comentarios a tus publicaciones con giscus o utterances"
date = 2023-07-14
description = "Descubre cómo habilitar una sección de comentarios en tus publicaciones usando giscus o utterances, permitiendo la interacción y feedback de los lectores."
[taxonomies]
tags = ["funcionalidad", "tutorial"]
[extra]
giscus = true
+++
tabi actualmente soporta dos sistemas de comentarios: [giscus](https://giscus.app/es) y [utterances](https://utteranc.es/).
giscus y utterances son proyectos de código abierto que te permiten añadir una sección de comentarios a tu sitio web usando las «issues» (utterances) o «discussions» (giscus) de GitHub. Son perfectos para generadores de sitios estáticos como Zola, ya que permiten a tus lectores interactuar y dejar comentarios en tus publicaciones sin requerir un backend tradicional ni una base de datos.
Al estar basados en GitHub, giscus y utterances requieren que los usuarios tengan una cuenta en dicha plataforma y autoricen la respectiva aplicación. Alternativamente, los visitantes también pueden comentar directamente en la discusión o «issue» correspondiente de GitHub.
Ambas son excelentes herramientas para agregar comentarios a tu blog, pero giscus tiene algunas ventajas:
- Más temas.
- Soporte para reacciones.
- Respuestas a comentarios y vista de conversación.
- Más seguro: utterances requiere habilitar estilos en línea inseguros («unsafe inline styles») para ajustar la altura del frame; giscus no.
- Soporte multilingüe: utterances solo está disponible en inglés; giscus soporta más de 20 idiomas.
- Desarrollo más activo: el último commit de giscus, a fecha de esta publicación, fue hace una semana. El último commit de utterances fue hace más de un año.
## Configuración
Cada sistema de comentarios requiere una configuración similar. Primero, visita el sitio web del sistema que quieres habilitar: [giscus.app](https://giscus.app/es) o [utteranc.es](https://utteranc.es/).
Sigue las instrucciones de la sección **Configuración** del sitio web, y elige las opciones que prefieras. Luego, establece los valores que se muestran en la sección **Habilitar giscus/utterances** (el bloque de código `script`) en la sección correspondiente de tu `config.toml`: `[extra.giscus]` o `[extra.utterances]`.
### giscus
giscus tiene algunos ajustes más que utterances:
```toml
[extra.giscus]
enabled_for_all_posts = false
automatic_loading = true
repo = "tuNombreDeUsuarioDeGithub/tuRepositorio"
repo_id = "TuIDdeRepositorio"
category = "Anuncios"
category_id = "TuIDdeCategoría"
mapping = "slug"
strict_title_matching = 1 # 1 para habilitar, 0 para deshabilitar.
enable_reactions = 1 # 1 para habilitar, 0 para deshabilitar.
comment_box_above_comments = true
light_theme = "noborder_light"
dark_theme = "noborder_dark"
lang = "" # Deja en blanco para que coincida con el idioma de la página.
lazy_loading = true
```
### utterances
```
[extra.utterances]
enabled_for_all_posts = false
automatic_loading = true
repo = "tuNombreDeUsuarioDeGithub/tuRepositorio"
issue_term = "slug"
label = "💬"
light_theme = "github-light"
dark_theme = "photon-dark"
lazy_loading = true
```
### Ajustes comunes
La opción `enabled_for_all_posts = true` habilitará globalmente el sistema de comentarios correspondiente.
Alternativamente, puedes habilitar los comentarios en publicaciones concretas con `utterances = true` o `giscus = true`. Por ejemplo, así habilitarías giscus:
```toml,hl_lines=09-10
+++
title = "Los molinos de viento de mi vida: reflexiones de un escudero"
date = 1605-01-16
description = "Mi viaje junto a Don Quijote, enfrentándome a gigantes imaginarios y descubriendo las verdaderas batallas de la vida."
[taxonomies]
tags = ["personal", "reflexiones"]
[extra]
giscus = true
+++
```
Si accidentalmente habilitas ambos sistemas, Zola mostrará un error.
Si tu web tiene múltiples idiomas con publicaciones coincidentes (como esta demo), y te gustaría compartir comentarios entre idiomas, debes usar `issue_term = "slug"`. Esto usará el nombre del archivo Markdown (sin la etiqueta de idioma) como identificador. Todas las demás opciones crearán diferentes secciones de comentarios para cada idioma.
## Ejemplo en vivo
Al final de esta publicación encontrarás el widget de giscus usando los ajustes mostrados [arriba](#giscus).

@ -0,0 +1,95 @@
+++
title = "Add comments to your posts with giscus or utterances"
date = 2023-07-14
description = "Discover how to enable a comments section on your posts using giscus or utterances, enabling reader interaction and feedback."
[taxonomies]
tags = ["showcase", "tutorial"]
[extra]
giscus = true
+++
tabi currently supports two comment systems: [giscus](https://giscus.app/) and [utterances](https://utteranc.es/).
giscus and utterances are open-source projects that let you add a comments section to your website using GitHub issues (utterances) or discussions (giscus). They are perfect for static site generators like Zola, since they enable your readers to interact and leave comments on your posts without requiring a traditional backend or database.
As they are based on GitHub, giscus and utterances require users to have a GitHub account and authorize the respective app. Alternatively, visitors can also comment directly on the corresponding GitHub discussion or issue.
Both are great tools for adding comments to your blog, but giscus has a few advantages:
- More themes.
- Support for reactions.
- Comment replies and conversation view.
- Safer: utterances requires enabling unsafe inline styles to set the height of the frame; giscus doesn't.
- Multilanguage support: utterances is only available in English; giscus supports over 20 languages.
- More active development: giscus' last commit, as of this post, was a week ago. utterances' last commit was over a year ago.
## Setup
The configuration of both systems is quite similar. First, visit the website of the system you want to enable: [giscus.app](https://giscus.app/) or [utteranc.es](https://utteranc.es/).
Follow the instructions on the **Configuration** section of the website, and set it up it to your liking. Then, set the values shown on the **Enable giscus/utterances** section (the `script` codeblock) on the proper section of your `config.toml`: `[extra.giscus]` or `[extra.utterances]`.
### giscus
giscus has a few more settings than utterances:
```toml
[extra.giscus]
enabled_for_all_posts = false
automatic_loading = true
repo = "yourGithubUsername/yourRepo"
repo_id = "YourRepoID"
category = "Announcements"
category_id = "YourCategoryID"
mapping = "slug"
strict_title_matching = 1 # 1 to enable, 0 to disable.
enable_reactions = 1 # 1 to enable, 0 to disable.
comment_box_above_comments = true
light_theme = "noborder_light"
dark_theme = "noborder_dark"
lang = "" # Leave blank to match the page's language.
lazy_loading = true
```
### utterances
```toml
[extra.utterances]
enabled_for_all_posts = false
automatic_loading = true
repo = "yourgithubuser/yourrepo"
issue_term = "slug"
label = "💬"
light_theme = "github-light"
dark_theme = "photon-dark"
lazy_loading = true
```
### Common settings
Setting `enabled_for_all_posts = true` for either comment system will enable it globally.
Alternatively, enable comments on an individual post's front matter by adding `utterances = true` or `giscus = true`. For example, this is how you would enable giscus:
```toml,hl_lines=09-10
+++
title = "Bears, Beets, Battlestar Galactica: The Dwight Schrute Guide to Life"
date = 2007-04-26
description = "Lessons learned from beet farming and paper sales."
[taxonomies]
tags = ["personal", "beets"]
[extra]
giscus = true
+++
```
If you accidentally enable both systems, your site will fail to build with an error.
If your site has multiple languages with matching posts (like this demo), and you'd like to share comments between languages, you must use `issue_term = "slug"`. This will use the name of the Markdown file (sans the language tag) as the identifier. All other options will create different comment sections for each language.
## Live example
Below you'll find the giscus widget using the settings shown [above](#giscus).

@ -1,22 +1,31 @@
+++
title = "Sense JavaScript obligatori"
date = 2023-01-06
updated = 2023-07-08
updated = 2023-07-13
description = "JavaScript només s'utilitza quan HTML i CSS no són suficients."
[taxonomies]
tags = ["funcionalitat"]
tags = ["funcionalitat", "tutorial"]
+++
## JavaScript?
Aquest tema funciona perfectament sense JavaScript. Opcionalment, pot carregar una quantitat mínima per afegir algunes funcionalitats que no són possibles utilitzant només HTML i CSS:
Aquest tema no requereix JavaScript obligatori. Opcionalment, pot carregar una quantitat mínima per afegir algunes característiques que són impossibles d'aconseguir amb HTML i CSS.
- **Canvi de mode clar/fosc**. S'activa establint `theme_switcher = true`. (~900 bytes)
- **Còpia de blocs de codi amb un sol clic**. S'activa establint `copy_button = true`. (~700 bytes)
### Opcions globals
Aquestes dues configuracions cal aplicar-les a la secció `[extra]` del fitxer `config.toml`.
- **Canvi de mode clar/fosc**. Habilitat configurant `theme_switcher = true`. (~900 bytes)
- **Còpia de blocs de codi amb un sol clic**. Habilitat configurant `copy_button = true`. (~700 bytes)
La [funcionalitat de KaTeX](@/blog/markdown.ca.md#katex), que requereix carregar un fitxer JavaScript de 274 KB, es pot activar per a publicacions específiques. Això es pot fer establint `katex = true` a la secció `[extra]` de l'encapçalament de la publicació.
Aquestes dues configuracions es poden aplicar a la secció `[extra]` del teu fitxer `config.toml`.
A part d'això, és un tema ràpid amb HTML i CSS. Tal i com hauria de ser (la major part de) la web :-)
- [**Comentaris**](@/blog/comments.ca.md). giscus (2 KB) o utterances (1 KB) es poden habilitar globalment configurant `enabled_for_all_posts = true` a la secció correcta de `config.toml` (`[extra.giscus]` o `[extra.utterances]`).
### Configuracions específiques de la pàgina
Les següents configuracions es poden habilitar en posts específics configurant certes variables a la secció `[extra]` del front matter de la publicació.
- [**KaTeX**](@/blog/markdown.ca.md#katex) (274 KB) es pot habilitar amb `katex = true`.
- [**Comentaris**](@/blog/comments.ca.md). Es poden habilitar a publicacions específiques assignant `utterances = true` o `giscus = true`.
A part d'això, és un tema ràpid amb HTML i CSS que funciona sense JavaScript. Just com hauria de ser (la majoria de) la web :-)

@ -1,22 +1,31 @@
+++
title = "Sin JavaScript obligatorio"
date = 2023-01-06
updated = 2023-07-08
updated = 2023-07-13
description = "JavaScript solo se utiliza cuando HTML y CSS no son suficientes."
[taxonomies]
tags = ["funcionalidad"]
tags = ["funcionalidad", "tutorial"]
+++
## ¿JavaScript?
Este tema funciona perfectamente sin JavaScript. Opcionalmente, puede cargar una cantidad mínima para añadir algunas funciones que son imposibles de lograr con HTML y CSS:
Este tema no tiene JavaScript obligatorio. Opcionalmente, puede cargar una cantidad mínima para agregar algunas características que son imposibles de lograr con HTML y CSS.
- **El cambio de modo claro/oscuro**. Habilitado estableciendo `theme_switcher = true`. (~900 bytes)
- **Copia de bloques de código con un clic**. Se activa configurando `copy_button = true`. (~700 bytes)
### Opciones globales
Estas dos configuraciones se deben aplicar en la sección `[extra]` de tu archivo `config.toml`.
- **Interruptor de modo claro/oscuro**. Habilitado configurando `theme_switcher = true`. (~900 bytes)
- **Copia de bloques de código con un solo clic**. Habilitado configurando `copy_button = true`. (~700 bytes)
La [funcionalidad de KaTeX](@/blog/markdown.es.md#katex), que requiere cargar un archivo JavaScript de 274 KB, se puede activar para publicaciones específicas. Esto se puede hacer configurando `katex = true` en la sección `[extra]` del encabezado de la publicación.
Estas dos configuraciones se pueden aplicar en la sección `[extra]` de tu `config.toml`.
Aparte de esto, es un tema rápido con HTML y CSS. Como debería ser (en su mayoría) la web :-)
- [**Comentarios**](@/blog/comments.es.md). giscus (2 KB) o utterances (1 KB) se pueden habilitar globalmente configurando `enabled_for_all_posts = true` en la sección apropiada de tu archivo `config.toml` (`[extra.giscus]` o `[extra.utterances]`).
### Opciones para publicaciones individuales
Las siguientes configuraciones se pueden habilitar en publicaciones específicas configurando ciertas variables en la sección `[extra]` del front matter del post.
- [**KaTeX**](@/blog/markdown.es.md#katex) (274 KB) se puede habilitar con `katex = true`.
- [**Comentarios**](@/blog/comments.es.md). Se pueden habilitar en posts específicos configurando `utterances = true` o `giscus = true`.
Aparte de eso, es un tema rápido con HTML y CSS que funciona con JavaScript deshabilitado. Como debería ser (en su mayoría) la web :-)

@ -1,22 +1,31 @@
+++
title = "No mandatory JavaScript"
date = 2023-01-06
updated = 2023-07-08
updated = 2023-07-13
description = "JavaScript is only used when HTML and CSS aren't enough."
[taxonomies]
tags = ["showcase"]
tags = ["showcase", "tutorial"]
+++
## JavaScript?
This theme has no mandatory JavaScript. Optionally, it can load a minimal amount to add some features that are impossible to achieve with HTML and CSS:
This theme has no mandatory JavaScript. Optionally, it can load a minimal amount to add some features that are impossible to achieve with HTML and CSS.
### Globally enabled settings
- **Light/dark mode switch**. Enabled by setting `theme_switcher = true`. (~900 bytes)
- **One-click copy of code blocks**. Enabled by setting `copy_button = true`. (~700 bytes)
These two settings can be applied in the `[extra]` section of your `config.toml` file.
[KaTeX support](@/blog/markdown.md#katex), which requires loading a 274 KB JavaScript file, can be activated for specific posts. This can be done by setting `katex = true` in the post's `[extra]` section of the post's front matter.
- [**Comments**](@/blog/comments.md). giscus (2 KB) or utterances (1 KB) can be globally enabled by setting `enabled_for_all_posts = true` in the right section of your `config.toml` (`[extra.giscus]` or `[extra.utterances]`).
### Page-specific settings
The following settings can be enabled on specific posts by setting certain variables in the `[extra]` section of the post's front matter.
- [**KaTeX** support](@/blog/markdown.md#katex) (274 KB) can be enabled it by setting `katex = true`.
- [**Comments**](@/blog/comments.md) can be enabled on individual posts by setting `utterances = true` or `giscus = true`.
Other than that, it's a fast site with HTML and CSS. Just the way (most of) the web should be :-)
Other than that, it's a fast theme with HTML and CSS which works with JavaScript disabled. Just the way (most of) the web should be :-)

@ -1,7 +1,7 @@
+++
title = "Seguretat per defecte"
date = 2023-02-22
updated = 2023-04-29
updated = 2023-07-14
description = "tabi té una Política de Seguretat de Contingut (CSP) fàcilment personalitzable amb valors segurs per defecte. Obtingues tranquil·litat i un A+ en l'Observatori de Mozilla."
[taxonomies]
@ -27,4 +27,6 @@ La llista `allowed_domains` especifica les URLs a les quals el lloc web hauria d
Aquesta funcionalitat permet personalitzar fàcilment les capçaleres de seguretat del lloc web per permetre casos d'ús específics, com ara inserir vídeos de YouTube, carregar scripts o tipografies remotes ([no recomanat](https://www.albertovarela.net/blog/2022/11/stop-using-google-fonts/)).
**Nota**: [habilitar els comentaris](@/blog/comments.ca.md) permet automàticament scripts i frames de utterances/giscus, així com estils en línia no segurs en el cas de utterances (necessari perquè el frame pugui ajustar la seva mida en funció del nombre de comentaris).
[^1]: Requereix una configuració adequada del servidor web (p. ex., redirigir el trànsit HTTP a HTTPS).

@ -1,7 +1,7 @@
+++
title = "Seguro por defecto"
date = 2023-02-22
updated = 2023-04-29
updated = 2023-07-14
description = "tabi tiene una Política de Seguridad de Contenido (CSP) fácilmente personalizable con configuraciones seguras. Obtén tranquilidad y una calificación de A+ en Mozilla Observatory."
[taxonomies]
@ -27,4 +27,6 @@ La lista `allowed_domains` especifica las URL a las que el sitio web debería po
Esta función permite personalizar fácilmente las cabeceras de seguridad del sitio web para permitir casos de uso específicos, como la incrustación de videos de YouTube, la carga de scripts o fuentes remotas ([no recomendado](https://www.albertovarela.net/blog/2022/11/stop-using-google-fonts/)).
**Nota**: [habilitar los comentarios](@/blog/comments.es.md) permite automáticamente scripts y frames de utterances/giscus, así como estilos unsafe-inline en el caso de utterances (necesario para que el frame pueda ajustar su tamaño en función del número de comentarios).
[^1]: Requiere una configuración adecuada del servidor web (por ejemplo, redirigir el tráfico HTTP a HTTPS).

@ -1,7 +1,7 @@
+++
title = "Secure by default"
date = 2023-02-22
updated = 2023-07-12
updated = 2023-07-14
description = "tabi has an easily customizable Content Security Policy (CSP) with safe defaults. Get peace of mind and an A+ on Mozilla Observatory."
[taxonomies]
@ -27,6 +27,6 @@ The `allowed_domains` list specifies the URLs that the website should be able to
This feature allows you to easily customize the website's security headers to allow for specific use cases, such as embedding YouTube videos, loading scripts or remote fonts ([not recommended](https://www.albertovarela.net/blog/2022/11/stop-using-google-fonts/)).
**Note**: enabling comments automatically allows scripts and frames from either utterances/giscus, as well as unsafe-inline styles when using utterances (required so that the widget can adjust its size based on the number of comments).
**Note**: [enabling comments](@/blog/comments.md) automatically allows scripts and frames from either utterances/giscus, as well as unsafe-inline styles when using utterances (required so that the frame can adjust its size based on the number of comments).
[^1]: Requires proper webserver configuration (e.g. redirecting HTTP traffic to HTTPS).

@ -4,6 +4,7 @@
.comments {
border-top: var(--divider-color) solid 0.5px;
border-bottom: var(--divider-color) solid 0.5px;
margin-top: 2rem;
padding-top: 2rem;
padding-bottom: 2rem;
@ -15,4 +16,18 @@
max-width: 100%;
aspect-ratio: inherit;
}
.load-comments-button {
display: inline-block;
font-family: var(--sans-serif-font);
color: inherit;
font-size: 0.95rem;
background: none;
border: none;
padding: 0.5em 1em;
margin: 0.5em;
cursor: pointer;
text-decoration: none;
}
}

@ -75,7 +75,5 @@ function initGiscus() {
}
}
// Initialize Giscus when the window loads.
window.addEventListener('load', () => {
initGiscus();
});
// Initialize Giscus.
initGiscus();

@ -1 +1 @@
function setGiscusTheme(t){var e=document.querySelector("iframe.giscus-frame");e&&e.contentWindow.postMessage({giscus:{setConfig:{theme:t}}},"https://giscus.app")}function initGiscus(){var t=document.querySelector(".comments");if(t){var e=t.getAttribute("data-repo"),a=t.getAttribute("data-repo-id"),i=t.getAttribute("data-category"),r=t.getAttribute("data-category-id"),d=t.getAttribute("data-strict"),s=t.getAttribute("data-term"),u=t.getAttribute("data-reactions-enabled"),n=t.getAttribute("data-input-position");const b=t.getAttribute("data-light-theme"),A=t.getAttribute("data-dark-theme");var o=t.getAttribute("data-lang"),c=t.getAttribute("data-lazy-loading"),g=document.createElement("script"),e=(g.src="https://giscus.app/client.js",g.async=!0,g.setAttribute("data-repo",e),g.setAttribute("data-repo-id",a),g.setAttribute("data-category",i),g.setAttribute("data-category-id",r),g.setAttribute("data-term",s),g.setAttribute("data-strict",d),g.setAttribute("data-reactions-enabled",u),g.setAttribute("data-emit-metadata","0"),g.setAttribute("data-input-position",n),g.setAttribute("data-lang",o),g.setAttribute("crossorigin","anonymous"),t.getAttribute("data-mapping")),a=(e&&g.setAttribute("data-mapping",e),document.documentElement.getAttribute("data-theme")||"light"),i="dark"===a?A:b;g.setAttribute("data-theme",i),"true"===c&&g.setAttribute("data-loading","lazy"),t.appendChild(g),window.addEventListener("themeChanged",t=>{setGiscusTheme("dark"===t.detail.theme?A:b)})}}window.addEventListener("load",()=>{initGiscus()});
function setGiscusTheme(t){var e=document.querySelector("iframe.giscus-frame");e&&e.contentWindow.postMessage({giscus:{setConfig:{theme:t}}},"https://giscus.app")}function initGiscus(){var t=document.querySelector(".comments");if(t){var e=t.getAttribute("data-repo"),a=t.getAttribute("data-repo-id"),i=t.getAttribute("data-category"),r=t.getAttribute("data-category-id"),d=t.getAttribute("data-strict"),s=t.getAttribute("data-term"),u=t.getAttribute("data-reactions-enabled"),n=t.getAttribute("data-input-position");const b=t.getAttribute("data-light-theme"),A=t.getAttribute("data-dark-theme");var o=t.getAttribute("data-lang"),c=t.getAttribute("data-lazy-loading"),g=document.createElement("script"),e=(g.src="https://giscus.app/client.js",g.async=!0,g.setAttribute("data-repo",e),g.setAttribute("data-repo-id",a),g.setAttribute("data-category",i),g.setAttribute("data-category-id",r),g.setAttribute("data-term",s),g.setAttribute("data-strict",d),g.setAttribute("data-reactions-enabled",u),g.setAttribute("data-emit-metadata","0"),g.setAttribute("data-input-position",n),g.setAttribute("data-lang",o),g.setAttribute("crossorigin","anonymous"),t.getAttribute("data-mapping")),a=(e&&g.setAttribute("data-mapping",e),document.documentElement.getAttribute("data-theme")||"light"),i="dark"===a?A:b;g.setAttribute("data-theme",i),"true"===c&&g.setAttribute("data-loading","lazy"),t.appendChild(g),window.addEventListener("themeChanged",t=>{setGiscusTheme("dark"===t.detail.theme?A:b)})}}initGiscus();

@ -0,0 +1,26 @@
// Wait for the full HTML document to be parsed and ready.
document.addEventListener('DOMContentLoaded', () => {
// Retrieve the button element.
const loadCommentsButton = document.querySelector('#load-comments');
// If the button exists…
if (loadCommentsButton) {
// Add a "click" event listener to the button.
loadCommentsButton.addEventListener('click', () => {
// Create a new "script" HTML element.
const script = document.createElement('script');
// Set the source of the script to the URL in the button's "data-script-src" attribute.
script.src = loadCommentsButton.dataset.scriptSrc;
// Load asynchronously.
script.async = true;
// Add the script element to the end of the document body, which causes the script to start loading and executing.
document.body.appendChild(script);
// Hide the button after it's clicked.
loadCommentsButton.style.display = 'none';
});
}
});

@ -0,0 +1 @@
document.addEventListener("DOMContentLoaded",()=>{const t=document.querySelector("#load-comments");t&&t.addEventListener("click",()=>{var e=document.createElement("script");e.src=t.dataset.scriptSrc,e.async=!0,document.body.appendChild(e),t.style.display="none"})});

@ -58,7 +58,5 @@ function initUtterances() {
}
}
// Initialize Utterances once the window has loaded.
window.addEventListener('load', () => {
initUtterances();
});
// Initialize Utterances.
initUtterances();

@ -1 +1 @@
function setUtterancesTheme(t){const e=document.querySelector(".utterances-frame");e&&e.contentWindow.postMessage({type:"set-theme",theme:t},"https://utteranc.es")}function initUtterances(){const t=document.querySelector(".comments");if(t){var e=t.getAttribute("data-repo"),a=t.getAttribute("data-issue-term"),r=t.getAttribute("data-label");const s=t.getAttribute("data-light-theme"),d=t.getAttribute("data-dark-theme");var n=t.getAttribute("data-lazy-loading"),i=document.createElement("script"),e=(i.src="https://utteranc.es/client.js",i.async=!0,i.setAttribute("repo",e),i.setAttribute("issue-term",a),i.setAttribute("label",r),document.documentElement.getAttribute("data-theme")||"light"),a="dark"===e?d:s;i.setAttribute("theme",a),i.setAttribute("crossorigin","anonymous"),"true"===n&&i.setAttribute("data-loading","lazy"),t.appendChild(i),window.addEventListener("themeChanged",t=>{setUtterancesTheme("dark"===t.detail.theme?d:s)})}}window.addEventListener("load",()=>{initUtterances()});
function setUtterancesTheme(t){const e=document.querySelector(".utterances-frame");e&&e.contentWindow.postMessage({type:"set-theme",theme:t},"https://utteranc.es")}function initUtterances(){const t=document.querySelector(".comments");if(t){var e=t.getAttribute("data-repo"),a=t.getAttribute("data-issue-term"),r=t.getAttribute("data-label");const s=t.getAttribute("data-light-theme"),d=t.getAttribute("data-dark-theme");var n=t.getAttribute("data-lazy-loading"),i=document.createElement("script"),e=(i.src="https://utteranc.es/client.js",i.async=!0,i.setAttribute("repo",e),i.setAttribute("issue-term",a),i.setAttribute("label",r),document.documentElement.getAttribute("data-theme")||"light"),a="dark"===e?d:s;i.setAttribute("theme",a),i.setAttribute("crossorigin","anonymous"),"true"===n&&i.setAttribute("data-loading","lazy"),t.appendChild(i),window.addEventListener("themeChanged",t=>{setUtterancesTheme("dark"===t.detail.theme?d:s)})}}initUtterances();

@ -8,8 +8,7 @@
{{ throw(message="ERROR: Multiple comment systems have been enabled for the same page. Check your config.toml and individual page settings to ensure only one comment system is activated at a time.") }}
{% elif giscus_enabled %}
{# Create a div to host giscus comments #}
<div class="comments"
<div class="comments centered-text"
{# Store required giscus data attributes in the div #}
data-repo="{{ config.extra.giscus.repo }}"
data-repo-id="{{ config.extra.giscus.repo_id }}"
@ -36,14 +35,17 @@
data-lang="{{ lang }}"
{% endif %}
data-lazy-loading="{{ config.extra.giscus.lazy_loading | default(value=true) }}">
</div>
{# giscus script to load the widget #}
<script src="{{ get_url(path='js/giscus_min.js', trailing_slash=false) | safe }}"/></script>
{% if config.extra.giscus.automatic_loading %}
<script src="{{ get_url(path='js/giscus_min.js', trailing_slash=false) | safe }}" async></script>
{% else %}
<button id="load-comments" class="load-comments-button" data-script-src="{{ get_url(path='js/giscus_min.js', trailing_slash=false) | safe }}">{%- if lang != config.default_language %} {{ trans(key="load_comments" | safe, lang=lang) }}{% else %} Load comments {%- endif -%}</button>
<script src="{{ get_url(path='js/loadComments_min.js', trailing_slash=false) | safe }}" async></script>
{% endif %}
</div>
{% elif utterances_enabled %}
{# Create a div to host utterances comments #}
<div class="comments"
<div class="comments centered-text"
{# Store required utterances data attributes in the div #}
data-repo="{{ config.extra.utterances.repo }}"
{% if config.extra.utterances.issue_term == "slug" %}
@ -55,10 +57,15 @@
data-light-theme="{{ config.extra.utterances.light_theme }}"
data-dark-theme="{{ config.extra.utterances.dark_theme }}"
data-lazy-loading="{{ config.extra.utterances.lazy_loading | default(value=true) }}">
{% if config.extra.utterances.automatic_loading %}
<script src="{{ get_url(path='js/utterances_min.js', trailing_slash=false) | safe }}" async></script>
{% else %}
<button id="load-comments" class="load-comments-button" data-script-src="{{ get_url(path='js/utterances_min.js', trailing_slash=false) | safe }}">{%- if lang != config.default_language %} {{ trans(key="load_comments" | safe, lang=lang) }}{% else %} Load comments {%- endif -%}</button>
<script src="{{ get_url(path='js/loadComments_min.js', trailing_slash=false) | safe }}" async></script>
{% endif %}
</div>
{# utterances script to load the widget #}
<script src="{{ get_url(path='js/utterances_min.js', trailing_slash=false) | safe }}"/></script>
{% endif %}
{%- endmacro add_comments -%}

@ -82,6 +82,7 @@
{# Add comments if they are enabled #}
{{ macros_add_comments::add_comments() }}
</article>
</main>

Loading…
Cancel
Save