Skip to content

Commit

Permalink
upgrade to astro-adocx 0.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
sransara committed Jul 11, 2024
1 parent 9aa36b8 commit 431e32d
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 35 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@
"asciidoc.preview.asciidoctorAttributes": {
"skip-front-matter": true
},
"asciidoc.antora.enableAntoraSupport": false,
}
27 changes: 17 additions & 10 deletions adocx/config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import path from 'node:path';

import type {
AdocNodeConverters,
AdocOptions,
AstroAdocxOptions,
} from '@sransara/astro-adocx/types';
// @ts-ignore: Types are not available
import { register as krokiPluginRegisterHandle } from 'asciidoctor-kroki';
import type { AdocOptions, AstroAdocxOptions, Template } from '@sransara/astro-adocx/types.js';

import { register as inlineMacroCalloutRegisterHandle } from './extensions/inlineMacroCallout';

const templates = Object.fromEntries(
Object.entries(import.meta.glob('./templates/*.ts', { eager: true })).map(([key, value]) => [
path.basename(key, '.ts'),
value as Template,
]),
);
const nodeConverters = Object.fromEntries(
Object.entries(import.meta.glob('./nodeConverters/*.ts', { eager: true, import: 'convert' })).map(
([key, value]) => [path.basename(key, '.ts'), value],
),
) as AdocNodeConverters;

const astroFenced = `
// For astro-layout-args
Expand All @@ -29,7 +32,13 @@ export const adocxConfig = {
// useful for asciidoctor-diagrams/kroki
document.setAttribute('outdir', path.dirname(filePath));
},
templates,
nodeConverters,
astroLayouts: {
note: {
path: '@/src/layouts/adocNoteLayout/AdocNoteLayout.astro',
args: 'poster={poster} metadata={metadata}',
},
},
} satisfies AstroAdocxOptions;

export const asciidoctorConfig = {
Expand All @@ -45,7 +54,5 @@ export const asciidoctorConfig = {
imagesdir: './_assets/',
'kroki-fetch-diagram': true,
'kroki-default-format': 'png',
'astro-layout-path': '@/src/layouts/adocNoteLayout/AdocNoteLayout.astro',
'astro-layout-args': '{...{ metadata, poster, docattrs, outline }}',
},
} satisfies AdocOptions;
2 changes: 1 addition & 1 deletion adocx/extensions/inlineMacroCallout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Extensions } from 'asciidoctor';

import { isExtensionSingleton } from '@sransara/astro-adocx/types.js';
import { isExtensionSingleton } from '@sransara/astro-adocx/types';

export function register(registry: typeof Extensions | Extensions.Registry) {
if (isExtensionSingleton(registry)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { UnsupportedNode, type AdocNodeConverter } from '@sransara/astro-adocx/types';
import { addOnceToAstroFence } from '@sransara/astro-adocx/utils/astroFence';
import type { Inline } from 'asciidoctor';
import { UnsupportedNode, type Template } from '@sransara/astro-adocx/types.js';
import { addOnceToAstroFence } from '@sransara/astro-adocx/utils/astroFence.js';

export const convert: Template<Inline>['convert'] = (node: Inline, _opts?: any) => {
export const convert: AdocNodeConverter<Inline> = (node: Inline, _opts?: any) => {
const nodeType = node.getType();
if (['asciimath', 'latexmath'].includes(nodeType)) {
addOnceToAstroFence(node, "import Mathtex from '@/src/lib/astro/mathtex/Mathtex.astro';");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Reference:
// - https://github.com/asciidoctor/asciidoctor-backends/blob/master/erb/html5/block_math.html.erb

import { type AdocNodeConverter } from '@sransara/astro-adocx/types';
import { addOnceToAstroFence } from '@sransara/astro-adocx/utils/astroFence';
import { atag } from '@sransara/astro-adocx/utils/asx';
import type { Block } from 'asciidoctor';
import { type Template } from '@sransara/astro-adocx/types.js';
import { addOnceToAstroFence } from '@sransara/astro-adocx/utils/astroFence.js';
import { atag } from '@sransara/astro-adocx/utils/asx.js';

export const convert: Template<Block>['convert'] = (node: Block, _opts?: any) => {
export const convert: AdocNodeConverter<Block> = (node: Block, _opts?: any) => {
const id = node.getId();
const title = node.getCaptionedTitle();
const roles = node.getRoles().join(' ');
Expand Down
8 changes: 4 additions & 4 deletions adocx/templates/stem.ts → adocx/nodeConverters/stem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// - https://github.com/asciidoctor/asciidoctor-backends/blob/master/erb/html5/block_math.html.erb

import type { Block } from 'asciidoctor';
import { type Template } from '@sransara/astro-adocx/types.js';
import { addOnceToAstroFence } from '@sransara/astro-adocx/utils/astroFence.js';
import { atag } from '@sransara/astro-adocx/utils/asx.js';
import { type AdocNodeConverter } from '@sransara/astro-adocx/types';
import { addOnceToAstroFence } from '@sransara/astro-adocx/utils/astroFence';
import { atag } from '@sransara/astro-adocx/utils/asx';

export const convert: Template<Block>['convert'] = (node: Block, _opts?: any) => {
export const convert: AdocNodeConverter<Block> = (node: Block, _opts?: any) => {
const id = node.getId();
const title = node.getCaptionedTitle();
const roles = node.getRoles().join(' ');
Expand Down
2 changes: 1 addition & 1 deletion astro.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sitemap from '@astrojs/sitemap';
import solid from '@astrojs/solid-js';
import tailwind from '@astrojs/tailwind';
import { adocx } from '@sransara/astro-adocx/integration.js';
import { adocx } from '@sransara/astro-adocx/integration';
import { defineConfig } from 'astro/config';

import { adocxConfig, asciidoctorConfig } from './adocx/config';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@astrojs/solid-js": "^4.4.0",
"@astrojs/tailwind": "^5.1.0",
"@eslint/js": "^9.6.0",
"@sransara/astro-adocx": "^0.0.13",
"@sransara/astro-adocx": "^0.0.14",
"@types/eslint": "^8.56.10",
"@types/eslint__js": "^8.42.3",
"@types/katex": "^0.16.7",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/layouts/adocNoteLayout/AdocNoteLayout.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import type { ImageMetadata } from 'astro';
import type { Outline } from '@sransara/astro-adocx/utils/outline.js';
import type { Outline } from '@sransara/astro-adocx/utils/outline';
import type { Metadata } from '@/src/lib/types/notes';
import NoteLayout from '@/src/layouts/noteLayout/NoteLayout.astro';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/astro/codeListing/CodeListing.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import { codeToHtml, bundledLanguages } from 'shiki';
import { decodeSpecialChars } from '@sransara/astro-adocx/utils/string.js';
import { decodeSpecialChars } from '@sransara/astro-adocx/utils/string';
interface Props {
lang: string;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/astro/mathtex/Mathtex.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import AsciiMathParser from 'asciimath2tex';
import { decodeSpecialChars } from '@sransara/astro-adocx/utils/string.js';
import { decodeSpecialChars } from '@sransara/astro-adocx/utils/string';
import katex, { type KatexOptions } from 'katex';
import 'katex/dist/katex.min.css';
Expand Down
1 change: 1 addition & 0 deletions src/pages/notes/2019/build-yourself-a-git/index.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Conceptually building up to the fundamentals datastructures of Git.
:sectnums:
:astro-layout: note

Have you ever wondered how Git works?
In this note we will incrementally build a version control system while taking inspiration from Git.
Expand Down
1 change: 1 addition & 0 deletions src/pages/notes/2019/hello-world/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Counter } from './_islands/Counter.jsx';
---
= Hello from another world.
:astro-layout: note

This is first contact.

Expand Down
2 changes: 1 addition & 1 deletion src/pages/notes/2023/bazel-python-venv/index.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
= Missing guide for creating a Python virtual environment in Bazel
:astro-layout-path: @/src/layouts/asciidocNoteLayout/AsciidocNoteLayout.astro
:astro-layout: note

Bazel provides great tooling for building and testing Python code, but https://github.com/bazelbuild/rules_python[rules_python] as of this note (2023-05-05) do not provide an obvious way to create a Python shell with the `PYTHONPATH` footnote:[A Python shell with the `PYTHONPATH` is what I call a Python virtual environment in this guide.].
As we venture outside the norms like `venv` by using Bazel, having access to a Python shell/enviroment lets us:
Expand Down
1 change: 1 addition & 0 deletions src/pages/notes/2023/power-to-tail-recursion/index.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
= Step by step tail recursion elimination of power function as an example
:astro-layout: note

[discrete]
=== TLDR
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["*"]
"@/*": ["./*"]
},
"checkJs": true,
"jsx": "preserve",
Expand Down

0 comments on commit 431e32d

Please sign in to comment.