✨ feat: add copy button to code blocks
This commit is contained in:
commit
ee6a54b3f9
@ -115,6 +115,9 @@ language_name.es = "Español"
|
||||
# The default setting is the light theme.
|
||||
theme_switcher = true
|
||||
|
||||
# Add a "copy" button to codeblocks (loads ~700 bytes of JavaScript).
|
||||
copy_button = true
|
||||
|
||||
# Date format used when listing posts (main page, /blog section, tag posts list…)
|
||||
# Default is "6th July 2049" in English and "%d %B %Y" in other languages.
|
||||
long_date_format = "%d %B %Y"
|
||||
|
@ -1,17 +0,0 @@
|
||||
+++
|
||||
title = "Gairebé sense JavaScript"
|
||||
date = 2023-01-06
|
||||
updated = 2023-04-28
|
||||
description = "JavaScript només s'utilitza quan HTML i CSS no són suficients."
|
||||
|
||||
[taxonomies]
|
||||
tags = ["funcionalitat"]
|
||||
+++
|
||||
|
||||
# JavaScript?
|
||||
|
||||
Aquest tema gairebé no utilitza JavaScript. Inclou uns ~900 bytes de fitxers `.js` amb la lògica per al canvi de tema clar/fosc, que es pot desactivar establint `theme_switcher = false` al fitxer `config.toml`.
|
||||
|
||||
La funcionalitat de KaTex, que requereix carregar un fitxer JavaScript de 274 KB, es pot activar per a publicacions específiques.
|
||||
|
||||
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 :-)
|
@ -1,17 +0,0 @@
|
||||
+++
|
||||
title = "Casi sin JavaScript"
|
||||
date = 2023-01-06
|
||||
updated = 2023-04-28
|
||||
description = "JavaScript solo se utiliza cuando HTML y CSS no son suficientes."
|
||||
|
||||
[taxonomies]
|
||||
tags = ["funcionalidad"]
|
||||
+++
|
||||
|
||||
# ¿JavaScript?
|
||||
|
||||
Este tema casi no utiliza JavaScript. Incluye ~900 bytes de código `.js` con la lógica para el interruptor de modo claro/oscuro, el cual puede ser desactivado configurando `theme_switcher = false` en el archivo `config.toml`.
|
||||
|
||||
El soporte de KaTeX, que requiere cargar un archivo JavaScript de 274 KB, puede ser activado para publicaciones específicas.
|
||||
|
||||
Aparte de esto, es un tema rápido con HTML y CSS. Como debería ser (en su mayoría) la web :-)
|
@ -1,17 +0,0 @@
|
||||
+++
|
||||
title = "Almost no JavaScript"
|
||||
date = 2023-01-06
|
||||
updated = 2023-04-28
|
||||
description = "JavaScript is only used when HTML and CSS aren't enough."
|
||||
|
||||
[taxonomies]
|
||||
tags = ["showcase"]
|
||||
+++
|
||||
|
||||
# JavaScript?
|
||||
|
||||
This theme has almost no JavaScript. It includes ~900 bytes of `.js` with the logic for the light/dark mode switch, which can be disabled by setting `theme_switcher = false` in the `config.toml` file.
|
||||
|
||||
KaTex support, which requires loading a 274 KB JavaScript file, can be activated for specific posts.
|
||||
|
||||
Other than that, it's a fast site with HTML and CSS. Just the way (most of) the web should be :-)
|
22
content/blog/javascript.ca.md
Normal file
22
content/blog/javascript.ca.md
Normal file
@ -0,0 +1,22 @@
|
||||
+++
|
||||
title = "Sense JavaScript obligatori"
|
||||
date = 2023-01-06
|
||||
updated = 2023-07-08
|
||||
description = "JavaScript només s'utilitza quan HTML i CSS no són suficients."
|
||||
|
||||
[taxonomies]
|
||||
tags = ["funcionalitat"]
|
||||
+++
|
||||
|
||||
## 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:
|
||||
|
||||
- **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)
|
||||
|
||||
Aquestes dues configuracions cal aplicar-les a la secció `[extra]` del fitxer `config.toml`.
|
||||
|
||||
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ó.
|
||||
|
||||
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 :-)
|
22
content/blog/javascript.es.md
Normal file
22
content/blog/javascript.es.md
Normal file
@ -0,0 +1,22 @@
|
||||
+++
|
||||
title = "Sin JavaScript obligatorio"
|
||||
date = 2023-01-06
|
||||
updated = 2023-07-08
|
||||
description = "JavaScript solo se utiliza cuando HTML y CSS no son suficientes."
|
||||
|
||||
[taxonomies]
|
||||
tags = ["funcionalidad"]
|
||||
+++
|
||||
|
||||
## ¿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:
|
||||
|
||||
- **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)
|
||||
|
||||
Estas dos configuraciones se deben aplicar en la sección `[extra]` de tu archivo `config.toml`.
|
||||
|
||||
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.
|
||||
|
||||
Aparte de esto, es un tema rápido con HTML y CSS. Como debería ser (en su mayoría) la web :-)
|
22
content/blog/javascript.md
Normal file
22
content/blog/javascript.md
Normal file
@ -0,0 +1,22 @@
|
||||
+++
|
||||
title = "No mandatory JavaScript"
|
||||
date = 2023-01-06
|
||||
updated = 2023-07-08
|
||||
description = "JavaScript is only used when HTML and CSS aren't enough."
|
||||
|
||||
[taxonomies]
|
||||
tags = ["showcase"]
|
||||
+++
|
||||
|
||||
## 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:
|
||||
|
||||
- **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.
|
||||
|
||||
Other than that, it's a fast site with HTML and CSS. Just the way (most of) the web should be :-)
|
@ -1,7 +1,7 @@
|
||||
+++
|
||||
title = "Exemples de Markdown"
|
||||
date = 2023-01-31
|
||||
updated = 2023-06-05
|
||||
updated = 2023-07-08
|
||||
description = "Aquesta publicació mostra alguns exemples de format en Markdown, incloent-hi una taula, blocs de codi i etiquetes, citacions, taules i notes a peu de pàgina."
|
||||
|
||||
[taxonomies]
|
||||
@ -23,7 +23,19 @@ Per mostrar l'expressió **en una línia pròpia i centrada**, embolcalla-la amb
|
||||
|
||||
Per exemple, `\\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]` es renderitzarà com: \\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]
|
||||
|
||||
Per activar $\KaTeX$ en una publicació, inclou `katex = true` dins de la secció `[extra]` dels metadades de la publicació. Per obtenir un millor rendiment i seguretat, els fitxers JavaScript, CSS i les tipografies s'allotgen localment.
|
||||
Per activar $\KaTeX$ en una publicació, inclou `katex = true` dins de la secció `[extra]` dels metadades de la publicació. Per exemple:
|
||||
|
||||
```toml,hl_lines=5-6
|
||||
+++
|
||||
title = "Provant KaTeX"
|
||||
date = 2002-11-30
|
||||
|
||||
[extra]
|
||||
katex = true
|
||||
+++
|
||||
```
|
||||
|
||||
Per obtenir un millor rendiment i seguretat, els fitxers JavaScript, CSS i les tipografies de $\KaTeX$ s'allotgen localment.
|
||||
|
||||
**Nota**: Després d'activar $\KaTeX$, si vols utilitzar el caràcter \$ sense renderitzar-lo com a expressió matemàtica, escapa'l amb una barra inversa: `\$`.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
+++
|
||||
title = "Ejemplos de Markdown"
|
||||
date = 2023-01-31
|
||||
updated = 2023-06-05
|
||||
updated = 2023-07-08
|
||||
description = "Esta publicación muestra algunos ejemplos de formato Markdown, incluyendo una tabla, bloques de código y etiquetas, citas, tablas y notas al pie de página."
|
||||
|
||||
[taxonomies]
|
||||
@ -23,7 +23,19 @@ Para mostrar la expresión **en su propia línea y centrada**, envuélvela entre
|
||||
|
||||
Por ejemplo, `\\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]` se mostraría como: \\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]
|
||||
|
||||
Para activar $\KaTeX$ en una publicación, incluye `katex = true` dentro de la sección `[extra]` del encabezado de la publicación. Para un mejor rendimiento y seguridad, el JavaScript, CSS y las fuentes se alojan localmente.
|
||||
Para activar $\KaTeX$ en una publicación, incluye `katex = true` dentro de la sección `[extra]` del encabezado de la publicación. Por ejemplo:
|
||||
|
||||
```toml,hl_lines=5-6
|
||||
+++
|
||||
title = "Probando KaTeX"
|
||||
date = 2002-11-30
|
||||
|
||||
[extra]
|
||||
katex = true
|
||||
+++
|
||||
```
|
||||
|
||||
Para un mejor rendimiento y seguridad, el JavaScript, CSS y las fuentes de $\KaTeX$ se alojan localmente.
|
||||
|
||||
**Nota**: Después de habilitar $\KaTeX$, si deseas usar \$ sin representar una expresión matemática, escápalo con una sola barra invertida: `\$`.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
+++
|
||||
title = "Markdown examples"
|
||||
date = 2023-01-31
|
||||
updated = 2023-06-05
|
||||
updated = 2023-07-08
|
||||
description = "This post showcases some examples of Markdown formatting, including a table, code blocks and tags, quotes, tables, and footnotes."
|
||||
|
||||
[taxonomies]
|
||||
@ -23,7 +23,19 @@ To display the expression **on its own line and centered**, wrap it around `$$`
|
||||
|
||||
For example, `\\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]` renders: \\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]
|
||||
|
||||
To activate $\KaTeX$ for a post, include `katex = true` within the `[extra]` section of the post's front matter. For enhanced performance and security, the JavaScript, CSS, and fonts are hosted locally.
|
||||
To activate $\KaTeX$ for a post, include `katex = true` within the `[extra]` section of the post's front matter. For exemple:
|
||||
|
||||
```toml,hl_lines=5-6
|
||||
+++
|
||||
title = "Testing KaTeX"
|
||||
date = 2002-11-30
|
||||
|
||||
[extra]
|
||||
katex = true
|
||||
+++
|
||||
```
|
||||
|
||||
For enhanced performance and security, the $\KaTeX$ JavaScript, CSS, and fonts are hosted locally.
|
||||
|
||||
**Note**: After enabling $\KaTeX$, if you want to use \$ without rendering a mathematical expression, escape it with a single backslash: `\$`.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
+++
|
||||
title = "Shortcodes personalitzats"
|
||||
date = 2023-02-19
|
||||
updated = 2023-07-05
|
||||
updated = 2023-07-07
|
||||
description = "Aquest tema inclou alguns shortcodes personalitzats útils que pots utilitzar per millorar les teves publicacions. Ja sigui per mostrar imatges que s'adapten als temes clar i fosc, o per donar format a una secció de referències amb un aspecte professional, aquests shortcodes personalitzats t'ajudaran."
|
||||
|
||||
[taxonomies]
|
||||
@ -39,7 +39,7 @@ Les imatges amb massa brillantor o contrast poden ser molestes en un fons fosc.
|
||||
|
||||
{{ dimmable_image(src="img/desert_by_oskerwyld.webp", alt="Fotografia d'un desert, cel celestial") }}
|
||||
|
||||
#### Usage
|
||||
#### Ús
|
||||
|
||||
```
|
||||
{{/* dimmable_image(src="img/desert_by_oskerwyld.webp", alt="Fotografia d'un desert, cel celestial") */}}
|
||||
|
@ -65,6 +65,8 @@
|
||||
--quote-color: #355f62;
|
||||
--border-color: #727272;
|
||||
--meta-color: #5b5b65;
|
||||
--codeblock-bg: #272430;
|
||||
--codeblock-highlight: #3d3949;
|
||||
|
||||
--theme-switcher-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M283.211 512c78.962 0 151.079-35.925 198.857-94.792 7.068-8.708-.639-21.43-11.562-19.35-124.203 23.654-238.262-71.576-238.262-196.954 0-72.222 38.662-138.635 101.498-174.394 9.686-5.512 7.25-20.197-3.756-22.23A258.156 258.156 0 0 0 283.211 0c-141.309 0-256 114.511-256 256 0 141.309 114.511 256 256 256z'/%3E%3C/svg%3E%0A");
|
||||
}
|
||||
@ -83,6 +85,8 @@
|
||||
--quote-color: #a9c5c7;
|
||||
--border-color: black;
|
||||
--meta-color: #B0B0B0;
|
||||
--codeblock-bg: #151515;
|
||||
--codeblock-highlight: #292929;
|
||||
|
||||
--theme-switcher-svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 96 960 960' %3E%3Cpath d='M480 776q-83 0-141.5-58.5T280 576q0-83 58.5-141.5T480 376q83 0 141.5 58.5T680 576q0 83-58.5 141.5T480 776ZM80 616q-17 0-28.5-11.5T40 576q0-17 11.5-28.5T80 536h80q17 0 28.5 11.5T200 576q0 17-11.5 28.5T160 616H80Zm720 0q-17 0-28.5-11.5T760 576q0-17 11.5-28.5T800 536h80q17 0 28.5 11.5T920 576q0 17-11.5 28.5T880 616h-80ZM480 296q-17 0-28.5-11.5T440 256v-80q0-17 11.5-28.5T480 136q17 0 28.5 11.5T520 176v80q0 17-11.5 28.5T480 296Zm0 720q-17 0-28.5-11.5T440 976v-80q0-17 11.5-28.5T480 856q17 0 28.5 11.5T520 896v80q0 17-11.5 28.5T480 1016ZM226 378l-43-42q-12-11-11.5-28t11.5-29q12-12 29-12t28 12l42 43q11 12 11 28t-11 28q-11 12-27.5 11.5T226 378Zm494 495-42-43q-11-12-11-28.5t11-27.5q11-12 27.5-11.5T734 774l43 42q12 11 11.5 28T777 873q-12 12-29 12t-28-12Zm-42-495q-12-11-11.5-27.5T678 322l42-43q11-12 28-11.5t29 11.5q12 12 12 29t-12 28l-43 42q-12 11-28 11t-28-11ZM183 873q-12-12-12-29t12-28l43-42q12-11 28.5-11t27.5 11q12 11 11.5 27.5T282 830l-42 43q-11 12-28 11.5T183 873Z'/%3E%3C/svg%3E");
|
||||
|
||||
@ -215,6 +219,10 @@ p {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
strong {
|
||||
font-weight: 620;
|
||||
}
|
||||
|
||||
.centered-text {
|
||||
text-align: center;
|
||||
}
|
||||
|
@ -2,98 +2,104 @@ code {
|
||||
background-color: var(--bg-1);
|
||||
padding: 0.1em 0.2em;
|
||||
font-family: var(--code-font);
|
||||
font-size: 0.9em;
|
||||
font-size: 0.9rem;
|
||||
|
||||
mark {
|
||||
background-color: var(--codeblock-highlight);
|
||||
color: inherit;
|
||||
filter: brightness(110%);
|
||||
display: block;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
margin: 0rem;
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0rem;
|
||||
|
||||
td,
|
||||
th,
|
||||
tr {
|
||||
border: none;
|
||||
padding: 0rem;
|
||||
}
|
||||
|
||||
tbody td:first-child {
|
||||
user-select: none;
|
||||
width: 2rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
tbody tr:nth-child(even) {
|
||||
background-color: inherit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pre {
|
||||
border: 1px solid var(--border-color);
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
display: block;
|
||||
line-height: 1.4;
|
||||
overflow-x: auto;
|
||||
padding: 1em;
|
||||
position: relative;
|
||||
padding: 2rem 1rem 1rem;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
border-radius: 5px;
|
||||
|
||||
code {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
white-space: pre;
|
||||
background-color: transparent;
|
||||
color: inherit;
|
||||
padding: 0rem;
|
||||
border: 0rem;
|
||||
border-radius: 5px;
|
||||
|
||||
&::before {
|
||||
content: attr(data-lang);
|
||||
display: block;
|
||||
background-color: var(--primary-color);
|
||||
color: var(--hover-color);
|
||||
padding: 0.3rem;
|
||||
padding-left: 1rem;
|
||||
width: calc(100% - 1.3rem);
|
||||
height: 0.9rem;
|
||||
font-size: 0.65rem;
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
text-transform: uppercase;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
&[class*="language-"] {
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pre code {
|
||||
background-color: transparent;
|
||||
color: inherit;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
pre code[class*="language-"] {
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
pre code[class*="language-"]::before {
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.025rem;
|
||||
padding: 0.1rem 0.5rem;
|
||||
.copy-code {
|
||||
z-index: 1;
|
||||
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960' %3E%3Cpath d='M217.002-67.694q-37.732 0-64.02-26.288-26.287-26.287-26.287-64.019V-707.69h77.999v549.689q0 4.615 3.846 8.462 3.846 3.846 8.462 3.846h451.689v77.999H217.002Zm175.999-175.999q-37.733 0-64.02-26.287T302.694-334v-463.383q0-37.732 26.287-64.02 26.287-26.287 64.02-26.287h365.383q37.732 0 64.019 26.287 26.288 26.288 26.288 64.02V-334q0 37.733-26.288 64.02-26.287 26.287-64.019 26.287H393.001Zm0-77.998h365.383q4.615 0 8.462-3.847 3.846-3.846 3.846-8.462v-463.383q0-4.616-3.846-8.462-3.847-3.846-8.462-3.846H393.001q-4.616 0-8.462 3.846-3.847 3.846-3.847 8.462V-334q0 4.616 3.847 8.462 3.846 3.847 8.462 3.847Zm-12.309 0v-488V-321.691Z'/%3E%3C/svg%3E");
|
||||
background: var(--hover-color);
|
||||
cursor: pointer;
|
||||
position: absolute;
|
||||
right: 0.1rem;
|
||||
margin-top: 0.1rem;
|
||||
text-align: right;
|
||||
text-transform: uppercase;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
pre code[class="language-javaScript"]::before,
|
||||
pre code[class="language-js"]::before {
|
||||
content: "js";
|
||||
background: #f7df1e;
|
||||
color: black;
|
||||
}
|
||||
|
||||
pre code[class*="language-yml"]::before,
|
||||
pre code[class*="language-yaml"]::before {
|
||||
content: "yaml";
|
||||
background: #C51117;
|
||||
height: 0.9rem;
|
||||
width: 0.9rem;
|
||||
background-size: contain;
|
||||
color: white;
|
||||
right: 0.7rem;
|
||||
top: 0.3rem;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
pre code[class*="language-shell"]::before,
|
||||
pre code[class*="language-bash"]::before,
|
||||
pre code[class*="language-sh"]::before {
|
||||
content: "shell";
|
||||
background: #33A841;
|
||||
color: white;
|
||||
.copy-code.checked {
|
||||
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960' %3E%3Cpath d='M395-253 194-455l83-83 118 117 288-287 83 84-371 371Z'/%3E%3C/svg%3E");
|
||||
height: 1rem;
|
||||
width: 1rem;
|
||||
}
|
||||
|
||||
pre code[class*="language-json"]::before {
|
||||
content: "json";
|
||||
color: black;
|
||||
background: whitesmoke;
|
||||
}
|
||||
|
||||
pre code[class*="language-python"]::before,
|
||||
pre code[class*="language-py"]::before {
|
||||
content: "python";
|
||||
background: #306698;
|
||||
color: #ffd343;
|
||||
}
|
||||
|
||||
pre code[class*="language-css"]::before {
|
||||
content: "css";
|
||||
background: #215AEF;
|
||||
color: white;
|
||||
}
|
||||
|
||||
pre code[class*="language-go"]::before {
|
||||
content: "Go";
|
||||
background: #00ADD8;
|
||||
color: white;
|
||||
}
|
||||
|
||||
pre code[class*="language-md"]::before,
|
||||
pre code[class*="language-md"]::before {
|
||||
content: "Markdown";
|
||||
background: #159ADC;
|
||||
color: white;
|
||||
}
|
||||
|
||||
pre code[class*="language-rust"]::before,
|
||||
pre code[class*="language-rs"]::before {
|
||||
content: "rust";
|
||||
background: #fff8f6;
|
||||
color: #ff4647;
|
||||
.copy-code.error {
|
||||
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960' %3E%3Cpath d='M479.386-248Q509-248 529-267.386q20-19.386 20-49T529.614-366.5q-19.386-20.5-49-20.5T431-366.886q-20 20.114-20 49.728t19.386 49.386q19.386 19.772 49 19.772ZM416-431h128v-265H416v265Zm64.276 381q-88.916 0-167.743-33.104-78.828-33.103-137.577-91.852-58.749-58.749-91.852-137.535Q50-391.277 50-480.458q0-89.438 33.162-167.491 33.163-78.053 92.175-136.942 59.011-58.889 137.533-91.999Q391.393-910 480.458-910q89.428 0 167.518 33.093T784.94-784.94q58.874 58.874 91.967 137.215Q910-569.385 910-480.192q0 89.192-33.11 167.518-33.11 78.326-91.999 137.337-58.889 59.012-137.167 92.174Q569.447-50 480.276-50Z'/%3E%3C/svg%3E");
|
||||
}
|
||||
|
@ -112,35 +112,6 @@ a:not(.no-hover-padding):hover::before {
|
||||
}
|
||||
}
|
||||
|
||||
table {
|
||||
justify-self: center;
|
||||
font: inherit;
|
||||
overflow: hidden;
|
||||
border-style: hidden !important;
|
||||
margin: 2rem 0;
|
||||
min-width: 400px;
|
||||
border: none;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
min-width: 13rem;
|
||||
}
|
||||
|
||||
table thead tr {
|
||||
background-color: var(--primary-color);
|
||||
color: var(--hover-color);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table th,
|
||||
table td {
|
||||
padding: 0.5em 0.7em;
|
||||
font-family: 'Source Serif Pro', serif;
|
||||
}
|
||||
|
||||
table tbody tr:nth-child(even) {
|
||||
background-color: var(--bg-0);
|
||||
}
|
||||
|
||||
.footnote-reference {
|
||||
font-family: var(--serif-font);
|
||||
font-size: 0.7rem;
|
||||
|
@ -1,15 +1,28 @@
|
||||
table {
|
||||
border-spacing: 0;
|
||||
border-collapse: collapse;
|
||||
justify-self: center;
|
||||
font: inherit;
|
||||
overflow: hidden;
|
||||
border-style: hidden !important;
|
||||
margin: 2rem auto;
|
||||
min-width: 13rem;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
table th {
|
||||
table th,
|
||||
table td {
|
||||
padding: 6px 13px;
|
||||
border: 1px solid #dfe2e5;
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
table td {
|
||||
padding: 6px 13px;
|
||||
border: 1px solid #dfe2e5;
|
||||
table thead tr {
|
||||
background-color: var(--primary-color);
|
||||
color: var(--hover-color);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
table tbody tr:nth-child(even) {
|
||||
background-color: var(--bg-0);
|
||||
}
|
||||
|
37
static/js/copyCodeToClipboard.js
Normal file
37
static/js/copyCodeToClipboard.js
Normal file
@ -0,0 +1,37 @@
|
||||
const changeIcon = (copyDiv, className) => {
|
||||
copyDiv.classList.add(className);
|
||||
setTimeout(() => copyDiv.classList.remove(className), 2500);
|
||||
};
|
||||
|
||||
const addCopyEventListenerToDiv = (copyDiv, block) => {
|
||||
copyDiv.addEventListener("click", () => copyCodeAndChangeIcon(copyDiv, block));
|
||||
};
|
||||
|
||||
const copyCodeAndChangeIcon = async (copyDiv, block) => {
|
||||
const code = block.querySelector('table') ? getTableCode(block) : getNonTableCode(block);
|
||||
try {
|
||||
await navigator.clipboard.writeText(code);
|
||||
changeIcon(copyDiv, "checked");
|
||||
} catch (error) {
|
||||
changeIcon(copyDiv, "error");
|
||||
}
|
||||
};
|
||||
|
||||
const getNonTableCode = (block) => {
|
||||
return [...block.querySelectorAll('code')]
|
||||
.map(code => code.textContent)
|
||||
.join('');
|
||||
};
|
||||
|
||||
const getTableCode = (block) => {
|
||||
return [...block.querySelectorAll('tr')]
|
||||
.map(row => row.querySelector('td:last-child')?.innerText ?? '')
|
||||
.join('');
|
||||
};
|
||||
|
||||
document.querySelectorAll("pre").forEach((block) => {
|
||||
const copyDiv = document.createElement("div");
|
||||
copyDiv.className = "copy-code";
|
||||
block.prepend(copyDiv);
|
||||
addCopyEventListenerToDiv(copyDiv, block);
|
||||
});
|
1
static/js/copyCodeToClipboard_min.js
Normal file
1
static/js/copyCodeToClipboard_min.js
Normal file
@ -0,0 +1 @@
|
||||
const changeIcon=(e,t)=>{e.classList.add(t),setTimeout(()=>e.classList.remove(t),2500)},addCopyEventListenerToDiv=(e,t)=>{e.addEventListener("click",()=>copyCodeAndChangeIcon(e,t))},copyCodeAndChangeIcon=async(e,t)=>{let o=t.querySelector("table")?getTableCode(t):getNonTableCode(t);try{await navigator.clipboard.writeText(o),changeIcon(e,"checked")}catch(c){changeIcon(e,"error")}},getNonTableCode=e=>[...e.querySelectorAll("code")].map(e=>e.textContent).join(""),getTableCode=e=>[...e.querySelectorAll("tr")].map(e=>e.querySelector("td:last-child")?.innerText??"").join("");document.querySelectorAll("pre").forEach(e=>{let t=document.createElement("div");t.className="copy-code",e.prepend(t),addCopyEventListenerToDiv(t,e)});
|
@ -22,11 +22,16 @@
|
||||
</div>
|
||||
{% include "partials/footer.html" %}
|
||||
|
||||
{% if page.extra.katex and page.extra.katex == true %}
|
||||
{# Add KaTeX functionality (loads CSS and JS) #}
|
||||
{%- if page.extra.katex and page.extra.katex == true -%}
|
||||
<link rel="stylesheet" href="{{ get_url(path='katex_min.css', trailing_slash=false) | safe }}">
|
||||
|
||||
<script defer src="{{ get_url(path='js/katex_min.js', trailing_slash=false) | safe }}"></script>
|
||||
{% endif %}
|
||||
{%- endif -%}
|
||||
|
||||
{# Add copy button to codeblocks #}
|
||||
{%- if config.extra.copy_button and config.extra.copy_button == true -%}
|
||||
<script defer src="{{ get_url(path='js/copyCodeToClipboard_min.js', trailing_slash=false) | safe }}"/></script>
|
||||
{%- endif -%}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
@ -69,7 +69,7 @@
|
||||
{%- endfor -%}
|
||||
{%- endif -%}">
|
||||
|
||||
{%- if config.extra.theme_switcher == true -%}
|
||||
{%- if config.extra.theme_switcher and config.extra.theme_switcher == true -%}
|
||||
<script type="text/javascript" src="{{ get_url(path='js/initialize_theme_min.js') | safe }}"></script>
|
||||
<script defer src="{{ get_url(path='js/main_min.js', trailing_slash=false) | safe }}"/></script>
|
||||
{%- endif -%}
|
||||
|
@ -62,7 +62,7 @@
|
||||
{%- endif %}
|
||||
|
||||
{# Theme switcher #}
|
||||
{%- if config.extra.theme_switcher == true -%}
|
||||
{%- if config.extra.theme_switcher and config.extra.theme_switcher == true -%}
|
||||
<li class="theme-switcher-wrapper">
|
||||
<div class="theme-switcher"></div>
|
||||
</li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user