Skip to content

Commit 7e6bd41

Browse files
committed
Add rehype-minify-url
1 parent 50f1fa7 commit 7e6bd41

File tree

8 files changed

+42
-13
lines changed

8 files changed

+42
-13
lines changed

generate/component/article/list.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @typedef Metadata
99
* @property {string | undefined} [description]
1010
* @property {ReadonlyArray<VFile> | undefined} [entries]
11+
* @property {string} origin
1112
* @property {string} pathname
1213
* @property {string | undefined} [slug]
1314
* @property {Array<string> | undefined} [tags]
@@ -19,18 +20,18 @@ import {item} from './item.js'
1920
import {more} from './more.js'
2021

2122
/**
22-
* @param {Metadata} section
23+
* @param {string} href
2324
* @param {Array<VFile>} d
2425
* @param {Options | undefined} [options]
2526
* @returns {Element}
2627
*/
27-
export function list(section, d, options) {
28+
export function list(href, d, options) {
2829
return cards(d, item, {more: map, ...options})
2930
/**
3031
* @param {number} rest
3132
* @returns {Element}
3233
*/
3334
function map(rest) {
34-
return more(section, rest)
35+
return more(href, rest)
3536
}
3637
}

generate/component/article/more.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {fmtCompact} from '../../util/fmt-compact.js'
77
import {fmtPlural} from '../../util/fmt-plural.js'
88

99
/**
10-
* @param {Metadata} section
10+
* @param {string} href
1111
* @param {number} rest
1212
*/
13-
export function more(section, rest) {
14-
return card(section.pathname, [
13+
export function more(href, rest) {
14+
return card(href, [
1515
'See ',
1616
fmtCompact(rest),
1717
' other ',

generate/index.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ import {topics} from './page/topics.js'
6464
import {topic} from './page/topic.js'
6565
import {data} from './data.js'
6666

67+
const origin = 'https://unifiedjs.com'
68+
6769
const users = /** @type {Array<ShowcaseUser>} */ (
6870
yaml.parse(
6971
await fs.readFile(new URL('../doc/showcase.yml', import.meta.url), 'utf8')
@@ -101,6 +103,7 @@ for (const d of input) {
101103
meta.type = 'article'
102104
meta.tags = [group]
103105
if (tags) meta.tags.push(...tags)
106+
meta.origin = origin
104107
meta.pathname = ['', 'learn', group, slug, ''].join('/')
105108

106109
entries.push(file)
@@ -138,6 +141,7 @@ for (const d of minidata) {
138141
sections.push({
139142
...d,
140143
entries: groupEntries,
144+
origin,
141145
pathname: '/learn/' + slug + '/',
142146
tags: [slug, 'learn']
143147
})
@@ -150,6 +154,7 @@ page(
150154
{
151155
description:
152156
'Content as structured data: unified compiles content and provides hundreds of packages to work with content',
157+
origin,
153158
pathname: '/'
154159
}
155160
)
@@ -165,7 +170,13 @@ for (const file of entries) {
165170

166171
for (const section of sections) {
167172
const {description, entries, pathname, tags, title} = section
168-
const meta = {description, pathname, tags, title}
173+
const meta = {
174+
description,
175+
origin,
176+
pathname,
177+
tags,
178+
title
179+
}
169180
assert(entries)
170181
page(function () {
171182
return articles(meta, entries)
@@ -178,6 +189,7 @@ page(
178189
},
179190
{
180191
description: 'Learn unified through guides and recipes',
192+
origin,
181193
pathname: '/learn/',
182194
tags: ['learn', 'recipe', 'guide', 'tutorial'],
183195
title: 'Learn'
@@ -190,6 +202,7 @@ page(
190202
},
191203
{
192204
description: 'Explore the unified ecosystem',
205+
origin,
193206
pathname: '/explore/',
194207
title: 'Explore'
195208
}
@@ -201,6 +214,7 @@ page(
201214
},
202215
{
203216
description: 'Explore packages in the unified ecosystem by keyword',
217+
origin,
204218
pathname: '/explore/keyword/',
205219
title: 'Keywords - Explore'
206220
}
@@ -216,6 +230,7 @@ for (const d of Object.keys(data.packagesByKeyword)) {
216230
'Explore packages in the unified ecosystem with the “' +
217231
d +
218232
'” keyword',
233+
origin,
219234
pathname: '/explore/keyword/' + d + '/',
220235
title: d + ' - Keywords'
221236
}
@@ -230,6 +245,7 @@ for (const d of Object.keys(data.packagesByScope)) {
230245
{
231246
description:
232247
'Explore packages in the unified ecosystem in the “' + d + '” scope',
248+
origin,
233249
pathname: '/explore/package/' + d + '/',
234250
title: d + ' - Scope'
235251
}
@@ -242,6 +258,7 @@ page(
242258
},
243259
{
244260
description: 'Explore projects in the unified ecosystem by topic',
261+
origin,
245262
pathname: '/explore/topic/',
246263
title: 'Topics - Explore'
247264
}
@@ -255,6 +272,7 @@ for (const d of Object.keys(data.projectsByTopic)) {
255272
{
256273
description:
257274
'Explore projects in the unified ecosystem with the “' + d + '” topic',
275+
origin,
258276
pathname: '/explore/topic/' + d + '/',
259277
title: d + ' - Topics'
260278
}
@@ -268,6 +286,7 @@ for (const d of Object.keys(data.projectsByOwner)) {
268286
},
269287
{
270288
description: 'Explore projects in the unified ecosystem by “@' + d + '”',
289+
origin,
271290
pathname: '/explore/project/' + d + '/',
272291
title: '@' + d + ' - Owner'
273292
}
@@ -280,6 +299,7 @@ page(
280299
},
281300
{
282301
description: 'Explore all packages in the unified ecosystem',
302+
origin,
283303
pathname: '/explore/package/',
284304
title: 'Packages - Explore'
285305
}
@@ -291,6 +311,7 @@ page(
291311
},
292312
{
293313
description: 'Explore all projects in the unified ecosystem',
314+
origin,
294315
pathname: '/explore/project/',
295316
title: 'Projects - Explore'
296317
}
@@ -302,6 +323,7 @@ page(
302323
},
303324
{
304325
description: 'Explore recent releases in the unified ecosystem',
326+
origin,
305327
pathname: '/explore/release/',
306328
title: 'Releases - Explore'
307329
}
@@ -316,6 +338,7 @@ for (const [d, p] of Object.entries(data.projectByRepo)) {
316338
},
317339
{
318340
description,
341+
origin,
319342
pathname: '/explore/project/' + d + '/',
320343
tags: [...topics],
321344
title: d
@@ -330,7 +353,7 @@ for (const [d, pack] of Object.entries(data.packageByName)) {
330353

331354
tasks.push(async function () {
332355
const file = await read(input)
333-
const meta = {description, pathname, tags: keywords, title: d}
356+
const meta = {description, origin, pathname, tags: keywords, title: d}
334357

335358
file.data = {meta, repo}
336359
const inputTree = readmePipeline.parse(file)
@@ -346,6 +369,7 @@ page(
346369
},
347370
{
348371
description: 'Get involved, meet the team, and support us',
372+
origin,
349373
pathname: '/community/',
350374
title: 'Community'
351375
}
@@ -357,6 +381,7 @@ page(
357381
},
358382
{
359383
description: 'Meet the team maintaining unified',
384+
origin,
360385
pathname: '/community/member/',
361386
title: 'Team - Community'
362387
}
@@ -368,6 +393,7 @@ page(
368393
},
369394
{
370395
description: 'Support unified by becoming a sponsor',
396+
origin,
371397
pathname: '/community/sponsor/',
372398
title: 'Sponsor - Community'
373399
}
@@ -379,6 +405,7 @@ page(
379405
},
380406
{
381407
description: 'Showcase of interesting use cases of unified',
408+
origin,
382409
pathname: '/community/case/',
383410
title: 'Showcase - Community'
384411
}

generate/page/articles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function articles(section, articles) {
2222
h('.row-l.column-l', {}, h('h2', {}, breadcrumbs(pathname, title))),
2323
[
2424
h('.article.content', [h('h3', {}, title), h('p', {}, description)]),
25-
list(section, helperSort(articles))
25+
list(section.pathname, helperSort(articles))
2626
]
2727
)
2828
}

generate/page/home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function home(data) {
106106
'make things with unified. '
107107
])
108108
]),
109-
articlesList({pathname: '/learn/'}, articlesSort(data.articles), {
109+
articlesList('/learn/', articlesSort(data.articles), {
110110
max: 6
111111
}),
112112
h('.article.content', [

generate/page/learn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function learn(sections) {
2222
assert(d.entries)
2323
articles.push(
2424
h('.article.content', [h('h3', {}, d.title), h('p', {}, d.description)]),
25-
list(d, helperSort(d.entries || []))
25+
list(d.pathname, helperSort(d.entries || []))
2626
)
2727
}
2828

generate/pipeline/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import assert from 'node:assert/strict'
77
import fs from 'node:fs/promises'
88
import rehypeDocument from 'rehype-document'
99
import rehypeMeta from 'rehype-meta'
10+
import rehypeMinifyUrl from 'rehype-minify-url'
1011
import rehypePresetMinify from 'rehype-preset-minify'
1112
import rehypePreventFaviconRequest from 'rehype-prevent-favicon-request'
1213
import rehypeStringify from 'rehype-stringify'
@@ -57,8 +58,6 @@ export const main = unified()
5758
},
5859
name: 'unified',
5960
og: true,
60-
origin: 'https://unifiedjs.com',
61-
pathname: '/',
6261
siteAuthor: 'unified collective',
6362
siteTags: ['ast', 'parse', 'process', 'stringify', 'transform', 'unified'],
6463
siteTwitter: '@unifiedjs',
@@ -68,6 +67,7 @@ export const main = unified()
6867
.use(rehypeDefer)
6968
.use(rehypePresetMinify)
7069
.use(rehypePreventFaviconRequest)
70+
.use(rehypeMinifyUrl)
7171
.use(move)
7272
.use(mkdir)
7373
.use(rehypeStringify)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"rehype-autolink-headings": "^7.0.0",
5252
"rehype-document": "^7.0.0",
5353
"rehype-meta": "^4.0.0",
54+
"rehype-minify-url": "^5.0.0",
5455
"rehype-parse": "^9.0.0",
5556
"rehype-preset-minify": "^7.0.0",
5657
"rehype-prevent-favicon-request": "^4.0.0",

0 commit comments

Comments
 (0)