@d10f/asciidoc-astro-loader 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -8
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -353,18 +353,27 @@ Using a converter might make more sense if you need to keep some state as the do
|
|
|
353
353
|
|
|
354
354
|
## Example
|
|
355
355
|
|
|
356
|
-
This is an example taken from my own website to showcase how to use it in a real world setting
|
|
356
|
+
This is an example taken from my own website to showcase how to use it in a real world setting:
|
|
357
357
|
|
|
358
358
|
```ts
|
|
359
359
|
const blog = defineCollection({
|
|
360
360
|
loader: asciidocLoader({
|
|
361
361
|
base: 'src/content/blog',
|
|
362
|
+
images: {
|
|
363
|
+
imageUrl: '/',
|
|
364
|
+
},
|
|
362
365
|
document: {
|
|
363
366
|
template: './src/templates',
|
|
364
|
-
converters: [
|
|
367
|
+
converters: [
|
|
368
|
+
admonitionConverter(),
|
|
369
|
+
xrefConverter()
|
|
370
|
+
],
|
|
365
371
|
},
|
|
366
372
|
syntaxHighlighting: {
|
|
367
|
-
theme:
|
|
373
|
+
theme: {
|
|
374
|
+
light: 'catppuccin-latte',
|
|
375
|
+
dark: 'catppuccin-frappe',
|
|
376
|
+
},
|
|
368
377
|
transformers: [
|
|
369
378
|
transformerNotationDiff(),
|
|
370
379
|
transformerNotationErrorLevel(),
|
|
@@ -373,6 +382,9 @@ const blog = defineCollection({
|
|
|
373
382
|
transformerPrompt({
|
|
374
383
|
langs: {
|
|
375
384
|
console: '$',
|
|
385
|
+
prolog: {
|
|
386
|
+
hideBreak: true,
|
|
387
|
+
},
|
|
376
388
|
},
|
|
377
389
|
cssClasses: 'unselectable mr-2 opacity-50',
|
|
378
390
|
}),
|
|
@@ -382,10 +394,38 @@ const blog = defineCollection({
|
|
|
382
394
|
},
|
|
383
395
|
},
|
|
384
396
|
}),
|
|
385
|
-
schema: z
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
397
|
+
schema: z
|
|
398
|
+
.object({
|
|
399
|
+
doctitle: z.string(),
|
|
400
|
+
description: z.string(),
|
|
401
|
+
revdate: z.coerce.date(),
|
|
402
|
+
keywords: z.string().transform((t) => t.split(', ')),
|
|
403
|
+
technologies: z.string().transform((t) => t.split(' ')),
|
|
404
|
+
series: z.string().optional(),
|
|
405
|
+
'series-prev': z.string().optional(),
|
|
406
|
+
'series-next': z.string().optional(),
|
|
407
|
+
'series-description': z.string().optional(),
|
|
408
|
+
})
|
|
409
|
+
.transform(({ doctitle, revdate, ...rest }) => ({
|
|
410
|
+
title: doctitle,
|
|
411
|
+
createdAt: revdate,
|
|
412
|
+
...rest,
|
|
413
|
+
})),
|
|
390
414
|
});
|
|
391
415
|
```
|
|
416
|
+
|
|
417
|
+
This configuration uses a couple of custom converters, a custom Shiki transformer and points to a folder where custom templates are found.
|
|
418
|
+
|
|
419
|
+
The first converter applies a simple CSS rule so that admonitions are placed on either side of the main document, in an alternate fashion.
|
|
420
|
+
|
|
421
|
+
The other converter is a little helper to rectify cross-reference links to other documents. I created it because cross-reference in AsciiDoc works by referencing a filename, whereas Astro uses the post title as the URL slug, which makes more sense in the context of the web. This converter handles the conversion so that I can keep things organized neatly based on what makes more sense: use filenames in the file system, and URL slugs in the web.
|
|
422
|
+
|
|
423
|
+
As for the custom Shiki transformer, that's just so that I control how code snippets look like when there's either a prefix expected, or when multi-line is supported. The classic example of this are console commands, but REPL interpreters are also a good example.
|
|
424
|
+
|
|
425
|
+
Here you can see it in action with a command that is written over multiple lines for clarity (horizontal overflow not shown here):
|
|
426
|
+
|
|
427
|
+

|
|
428
|
+
|
|
429
|
+
Notice the escaping of the newline character, which you might want to omit with the `hideBreak` option. This is useful to distinguish code from REPL interpreters:
|
|
430
|
+
|
|
431
|
+

|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d10f/asciidoc-astro-loader",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "An Astro collections loader for Asciidoc files",
|
|
5
5
|
"author": "D10f",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"tsup": "^8.5.0",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"typescript-eslint": "^8.45.0",
|
|
50
|
-
"vitest": "^
|
|
50
|
+
"vitest": "^5.0.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@shikijs/transformers": "^
|
|
53
|
+
"@shikijs/transformers": "^4.5.0",
|
|
54
54
|
"asciidoctor": "^3.0.4",
|
|
55
|
-
"shiki": "^
|
|
55
|
+
"shiki": "^4.5.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"astro": "^6.3.1"
|