Skip to content

Commit 912c168

Browse files
committed
feat: add toc to articles
1 parent 61d9189 commit 912c168

File tree

8 files changed

+44
-18
lines changed

8 files changed

+44
-18
lines changed

.eleventy.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const EleventyPluginNavigation = require('@11ty/eleventy-navigation')
22
const EleventyPluginRss = require('@11ty/eleventy-plugin-rss')
33
const EleventyPluginSyntaxhighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
4-
// const EleventyPluginReadingTime = require('eleventy-plugin-reading-time')
54
const EleventyVitePlugin = require('@11ty/eleventy-plugin-vite')
65
const { EleventyI18nPlugin } = require("@11ty/eleventy")
76
const rollupPluginCritical = require('rollup-plugin-critical').default
@@ -17,6 +16,7 @@ const { execSync } = require('child_process')
1716
// markdown
1817
const markdownIt = require('markdown-it')
1918
const markdownItAnchor = require('markdown-it-anchor')
19+
const markdownItTocDoneRight = require('markdown-it-toc-done-right')
2020

2121
// image gallery
2222
const Image = require('@11ty/eleventy-img')
@@ -27,22 +27,20 @@ const LANDSCAPE_LIGHTBOX_IMAGE_WIDTH = 1440;
2727
const PORTRAIT_LIGHTBOX_IMAGE_WIDTH = 720;
2828

2929
module.exports = function (eleventyConfig) {
30-
// eleventyConfig.setServerPassthroughCopyBehavior('copy')
3130
eleventyConfig.addPassthroughCopy("public")
3231

3332
// plugins
3433
eleventyConfig.addPlugin(EleventyPluginNavigation)
3534
eleventyConfig.addPlugin(EleventyPluginRss)
3635
eleventyConfig.addPlugin(EleventyPluginSyntaxhighlight)
37-
// eleventyConfig.addPlugin(EleventyPluginReadingTime)
3836
eleventyConfig.addPlugin(EleventyI18nPlugin, {
3937
defaultLanguage: "en",
4038
errorMode: "never"
4139
})
4240
eleventyConfig.addPlugin(EleventyVitePlugin, {
4341
tempFolderName: './.11ty-vite',
4442
viteOptions: {
45-
base: '/', // '/danieletabellini/',
43+
base: '/',
4644
publicDir: 'public',
4745
clearScreen: false,
4846
server: {
@@ -68,8 +66,8 @@ module.exports = function (eleventyConfig) {
6866
chunkFileNames: 'assets/js/[name]-[hash].js',
6967
entryFileNames: 'assets/js/[name]-[hash].js',
7068
manualChunks: {
71-
// PhotoSwipe: ['photoswipe'],
72-
// PhotoSwipeLightbox: ['photoswipe/lightbox'],
69+
PhotoSwipe: ['photoswipe'],
70+
PhotoSwipeLightbox: ['photoswipe/lightbox'],
7371
}
7472
},
7573
plugins: [rollupPluginCritical({
@@ -129,10 +127,8 @@ module.exports = function (eleventyConfig) {
129127
let imageSrc = `${path.dirname(this.page.inputPath)}/${src}`
130128
let lightboxImageWidth = LANDSCAPE_LIGHTBOX_IMAGE_WIDTH
131129
if (alt === undefined) throw new Error(`Missing \`alt\` on image from: ${src}`)
132-
133130
let metadata = await sharp(imageSrc).metadata()
134131
if (metadata.height > metadata.width) lightboxImageWidth = PORTRAIT_LIGHTBOX_IMAGE_WIDTH
135-
136132
let genMetadata = await Image(imageSrc, {
137133
widths: [GALLERY_IMAGE_WIDTH, lightboxImageWidth],
138134
formats: ["avif", "webp", "jpeg"],
@@ -143,7 +139,6 @@ module.exports = function (eleventyConfig) {
143139
const imageWidth = genMetadata.jpeg[1].width
144140
const imageHeight = genMetadata.jpeg[1].height
145141
const thumbUrl = eleventyConfig.getFilter("url")(genMetadata.jpeg[0].url)
146-
147142
return `
148143
<li>
149144
<a href="${imageUrl}"
@@ -155,6 +150,7 @@ module.exports = function (eleventyConfig) {
155150
</li>
156151
`.replace(/(\r\n|\n|\r)/gm, "")
157152
})
153+
158154
// Paired shortcodes
159155
Object.keys(pairedShortcodes).forEach((pairedShortcodeName) => {
160156
eleventyConfig.addPairedLiquidShortcode(pairedShortcodeName, pairedShortcodes[pairedShortcodeName])
@@ -166,12 +162,12 @@ module.exports = function (eleventyConfig) {
166162
breaks: true,
167163
linkify: true
168164
}).use(markdownItAnchor, {
169-
permalink: markdownItAnchor.permalink.ariaHidden({
170-
placement: 'after',
171-
class: 'direct-link',
172-
symbol: '#',
173-
level: [1, 2, 3, 4]
174-
}),
165+
level: [2],
166+
slugify: eleventyConfig.getFilter('slug')
167+
}).use(markdownItTocDoneRight, {
168+
containerClass: "toc",
169+
containerId: "toc",
170+
level: [2],
175171
slugify: eleventyConfig.getFilter('slug')
176172
})
177173
eleventyConfig.setLibrary('md', markdownLibrary)

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"focus-visible": "^5.2.0",
4747
"luxon": "^3.0.1",
4848
"markdown-it": "^14.0.0",
49-
"markdown-it-anchor": "^8.6.4",
49+
"markdown-it-anchor": "^8.6.7",
5050
"npm-run-all": "^4.1.5",
5151
"pagefind": "^0.12.0",
5252
"postcss-nesting": "^12.0.1",
@@ -56,6 +56,7 @@
5656
},
5757
"dependencies": {
5858
"child_process": "^1.0.2",
59+
"markdown-it-toc-done-right": "^4.2.0",
5960
"photoswipe": "^5.3.7"
6061
}
6162
}

src/assets/css/5-elements/_body.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ body {
44
padding-right: var(--scrollbarComp);
55
overflow-x: hidden;
66
}
7+
8+
html, body {
9+
scroll-behavior: smooth;
10+
}

src/assets/css/5-elements/_lists.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ol {
1212
li > {
1313

1414
a {
15-
padding: var(--spacing-xx-small);
15+
padding: var(--spacing-x-small);
1616
}
1717

1818
ul,

src/assets/css/7-components/_toc.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
nav.toc {
2+
padding-top: var(--spacing-x-small);
3+
padding-bottom: var(--spacing-xx-small);
4+
ol {
5+
counter-reset: index;
6+
}
7+
8+
li {
9+
display: block;
10+
counter-increment: index;
11+
12+
&:before {
13+
content: counters(index, '.', decimal-leading-zero) ' ';
14+
}
15+
}
16+
}

src/assets/css/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
@use "7-components/notelist";
4141
@use "7-components/pagefind-ui";
4242
@use "7-components/taglist";
43+
@use "7-components/toc";
4344

4445
// 8. Utilities
4546
@use "8-utilities/modifiers";

src/it/notes/2023-04-21-style-guide.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Guida di stile
33
tags: [Design]
44
---
55

6+
[[toc]]
7+
68
## headings (h2)
79
### h3
810
#### h4

0 commit comments

Comments
 (0)