-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
order: -1 | ||
--- | ||
{#config-reference} | ||
# Configuration reference | ||
|
||
{tag=aside .caution} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Version directives | ||
|
||
{added-in-version="0.0.5"} | ||
::: | ||
::: | ||
|
||
You can mark some content as applying to a specific version using the `added-in-version` attribute on an empty div. If you specified a `projectInfo.version`{.language-yaml} in your [configuration](#config-reference), and the specified version is greater, then the message will be future-tense. | ||
|
||
```djot | ||
{added-in-version="0.0.1"} | ||
::: | ||
::: | ||
|
||
{added-in-version="10.0"} | ||
::: | ||
::: | ||
``` | ||
|
||
Output: | ||
|
||
{added-in-version="0.0.1"} | ||
::: | ||
::: | ||
|
||
{added-in-version="10.0"} | ||
::: | ||
::: | ||
|
||
You can also put content inside if you want to add commentary. | ||
|
||
```djot | ||
{added-in-version="10.0"} | ||
::: | ||
We're really excited about this feature! | ||
::: | ||
``` | ||
|
||
Output: | ||
|
||
{added-in-version="10.0"} | ||
::: | ||
We're really excited about this feature! | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { DjockeyConfig, DjockeyDoc, DjockeyPlugin } from "../types.js"; | ||
import { applyFilter } from "../engine/djotFiltersPlus.js"; | ||
import { getAnyAttribute } from "../util.js"; | ||
import { Block } from "@djot/djot"; | ||
|
||
function normalizeSemverString(semverString: string): [number, number, number] { | ||
const parts: number[] = semverString | ||
.split(".") | ||
.map((s) => parseInt(s, 10)) | ||
.slice(0, 3); | ||
while (parts.length < 3) parts.push(0); | ||
return parts as [number, number, number]; | ||
} | ||
|
||
function isSemverGreaterOrEqual(a: string, b: string): boolean { | ||
const aParts = normalizeSemverString(a); | ||
const bParts = normalizeSemverString(b); | ||
for (let i = 0; i < 3; i++) { | ||
if (aParts[i] > bParts[i]) return true; | ||
if (aParts[i] < bParts[i]) return false; | ||
} | ||
return true; | ||
} | ||
|
||
type Cls = | ||
| "added-in-version" | ||
| "changed-in-version" | ||
| "removed-in-version" | ||
| "deprecated-in-version"; | ||
const PREFIXES_CURRENT: Record<Cls, string> = { | ||
"added-in-version": "Added in version", | ||
"changed-in-version": "Changed in version", | ||
"removed-in-version": "Removed in version", | ||
"deprecated-in-version": "Deprecated in version", | ||
}; | ||
|
||
const PREFIXES_FUTURE: Record<Cls, string> = { | ||
"added-in-version": "Will be added in version", | ||
"changed-in-version": "Will be changed in version", | ||
"removed-in-version": "Will be reemoved in version", | ||
"deprecated-in-version": "Will be deprecated in version", | ||
}; | ||
|
||
export class VersionDirectivesPlugin implements DjockeyPlugin { | ||
name = "Version Directives"; | ||
|
||
constructor(public config: DjockeyConfig) {} | ||
|
||
onPass_write(doc: DjockeyDoc) { | ||
const projectVersion = this.config.projectInfo?.version; | ||
applyFilter(doc.docs.content, () => ({ | ||
div: (node) => { | ||
const keyAndValue = getAnyAttribute( | ||
node, | ||
Object.keys(PREFIXES_CURRENT) | ||
); | ||
if (!keyAndValue) return; | ||
const [key, value] = keyAndValue; | ||
|
||
// If no project version, assume it's already release. Otherwise, put it in the future. | ||
const prefix = | ||
!projectVersion || isSemverGreaterOrEqual(projectVersion, value) | ||
? PREFIXES_CURRENT[key as Cls] | ||
: PREFIXES_FUTURE[key as Cls]; | ||
return buildAST(key, `${prefix} ${value}`, node.children); | ||
}, | ||
})); | ||
} | ||
} | ||
|
||
function buildAST(cls: string, text: string, children: Block[]): Block { | ||
return { | ||
tag: "div", | ||
attributes: { class: `version-modified ${cls}` }, | ||
children: [ | ||
{ | ||
tag: "para", | ||
attributes: { class: "primary" }, | ||
children: [{ tag: "str", text }], | ||
}, | ||
...structuredClone(children), | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters