Comparing version 1.9.1 to 1.10.0
@@ -8,2 +8,8 @@ # Change Log | ||
## [1.10.0] - 2024-06-03 | ||
### Changed | ||
- the `VarRegexReplacer` used by `StringEchoVarReplaceCommand` and `SsiEchoVarCommand` defaults to generic replacements when no variable name is specified. | ||
## [1.9.1] - 2024-05-20 | ||
@@ -51,2 +57,3 @@ | ||
### Changed | ||
- `SsgContext.read(filename)` becomes `SsgContext.getInputFrom(filename)` to denote it affects the context's `inputFile`. | ||
@@ -59,2 +66,3 @@ - `SsgContext.readOrNew(filename, dir)` becomes `SsgContext.setOutputFrom(filename)` to denote it affects the context's `outputFile`. | ||
### Fixed | ||
HTML lang overrides lang from filename. | ||
@@ -65,5 +73,7 @@ | ||
### Fixed | ||
Update document title from SsgFile title. | ||
### Changed | ||
`ContentStep.processFile()` hasn't `fileCount` parameter anymore and returns a `boolean`. | ||
@@ -74,2 +84,3 @@ | ||
### Changed | ||
Replaced native charset detection by JS one. | ||
@@ -80,5 +91,7 @@ | ||
### Added | ||
Add `generator` meta info as `ssg-api` by default. | ||
### Fixed | ||
Serialize meta info. | ||
@@ -89,2 +102,3 @@ | ||
### Added | ||
`ReplaceCommand.contentStepEnd()` callback when the relevant ContentStep is terminating. | ||
@@ -95,2 +109,3 @@ | ||
### Fixed | ||
`FileUtil.ssgCopy()` removed `cpy` dependency which has a bug causing output dir not always applied. | ||
@@ -101,2 +116,3 @@ | ||
### Fixed | ||
Replaced jest by testscript | ||
@@ -120,3 +136,3 @@ | ||
- Read files from context now read HTML files as such. | ||
- Read files from context now read HTML files as such. | ||
@@ -127,3 +143,3 @@ ## [1.4.3] - 2023-04-23 | ||
- Read files from context now read HTML files as such. | ||
- Read files from context now read HTML files as such. | ||
@@ -130,0 +146,0 @@ ## [1.4.2] - 2023-01-22 |
@@ -73,3 +73,3 @@ import fs from "fs"; | ||
else { | ||
context.debug("Not orocessing", filePath); | ||
context.debug("Skipping", filePath); | ||
} | ||
@@ -76,0 +76,0 @@ return processed; |
@@ -10,6 +10,10 @@ export class DomReplaceCommand { | ||
const replacer = await this.createReplacer(context); | ||
const doc = inputFile.document; | ||
if (!doc) { | ||
throw Error(inputFile.name + " has is not an HTML file"); | ||
} | ||
const docEl = doc.documentElement; | ||
do { | ||
contents = result; | ||
const doc = inputFile.document.documentElement; | ||
const elements = doc.querySelectorAll(this.selector); | ||
const elements = docEl.querySelectorAll(this.selector); | ||
if (elements.length > 0) { | ||
@@ -16,0 +20,0 @@ for (const element of elements) { |
@@ -9,6 +9,5 @@ import { RegexReplaceCommand } from "../../RegexReplaceCommand.js"; | ||
export declare class SsiEchoVarReplaceCommand<V = any, C extends HtmlSsgContext<V> = HtmlSsgContext<V>> extends RegexReplaceCommand<V, HtmlSsgContext<V>> { | ||
protected varName: string; | ||
protected defaultHandlers: StringContextHandler[]; | ||
constructor(varName: string, defaultHandlers?: StringContextHandler[]); | ||
constructor(varName?: string, defaultHandlers?: StringContextHandler[]); | ||
protected createReplacer(context: C): Promise<RegexReplacer>; | ||
} |
@@ -7,10 +7,9 @@ import { RegexReplaceCommand } from "../../RegexReplaceCommand.js"; | ||
export class SsiEchoVarReplaceCommand extends RegexReplaceCommand { | ||
constructor(varName, defaultHandlers = []) { | ||
super(new RegExp(`<!--\\s*#echo\\s+var="${String(varName)}"\\s*-->`, "gs")); | ||
this.varName = varName; | ||
constructor(varName = "(.*?)", defaultHandlers = []) { | ||
super(new RegExp(`<!--\\s*#echo\\s+var="${varName}"\\s*-->`, "gs")); | ||
this.defaultHandlers = defaultHandlers; | ||
} | ||
async createReplacer(context) { | ||
return new VarRegexReplacer(context, this.varName, this.defaultHandlers); | ||
return new VarRegexReplacer(context, this.defaultHandlers); | ||
} | ||
} |
@@ -6,6 +6,5 @@ import { RegexReplaceCommand } from "../RegexReplaceCommand.js"; | ||
export declare class StringEchoVarReplaceCommand<V = any, C extends SsgContext = SsgContext<V>> extends RegexReplaceCommand<V, C> { | ||
protected varName: string; | ||
protected defaultHandlers: StringContextHandler[]; | ||
constructor(varName: string, defaultHandlers?: StringContextHandler[]); | ||
constructor(varName?: string, defaultHandlers?: StringContextHandler[]); | ||
protected createReplacer(context: SsgContext<V>): Promise<RegexReplacer>; | ||
} |
import { RegexReplaceCommand } from "../RegexReplaceCommand.js"; | ||
import { VarRegexReplacer } from "./VarRegexReplacer.js"; | ||
export class StringEchoVarReplaceCommand extends RegexReplaceCommand { | ||
constructor(varName, defaultHandlers = []) { | ||
super(new RegExp(`\\$\{${String(varName)}\}`, "gs")); | ||
this.varName = varName; | ||
constructor(varName = "(.*?)", defaultHandlers = []) { | ||
super(new RegExp(`\\$\{${varName}\}`, "gs")); | ||
this.defaultHandlers = defaultHandlers; | ||
} | ||
async createReplacer(context) { | ||
return new VarRegexReplacer(context, this.varName, this.defaultHandlers); | ||
return new VarRegexReplacer(context, this.defaultHandlers); | ||
} | ||
} |
import { RegexReplacer } from "../RegexReplacer.js"; | ||
import { StringContextHandler } from "./StringContextHandler.js"; | ||
import { SsgContext } from "../../../../SsgContext.js"; | ||
export declare class VarRegexReplacer<V = any, C extends SsgContext = SsgContext> implements RegexReplacer { | ||
export declare class VarRegexReplacer<C extends SsgContext = SsgContext> implements RegexReplacer { | ||
protected context: C; | ||
protected varName: string; | ||
protected defaultHandlers: StringContextHandler<C>[]; | ||
constructor(context: C, varName: string, defaultHandlers: StringContextHandler<C>[]); | ||
replace(_match: string, ..._args: any[]): string; | ||
constructor(context: C, defaultHandlers: StringContextHandler<C>[]); | ||
replace(_match: string, ...args: any[]): string; | ||
} |
export class VarRegexReplacer { | ||
constructor(context, varName, defaultHandlers) { | ||
constructor(context, defaultHandlers) { | ||
this.context = context; | ||
this.varName = varName; | ||
this.defaultHandlers = defaultHandlers; | ||
} | ||
replace(_match, ..._args) { | ||
let varStr = this.context.getVar(this.varName); | ||
replace(_match, ...args) { | ||
let varStr = this.context.getVar(args[0]); | ||
if (!varStr) { | ||
@@ -10,0 +9,0 @@ this.defaultHandlers.some(handle => !varStr && (varStr = handle(this.context))); |
@@ -22,3 +22,3 @@ /** | ||
result = contents.replace(this.regex, replaceFunc); | ||
} while (result != contents); | ||
} while (result !== contents); | ||
context.file.contents = result; | ||
@@ -25,0 +25,0 @@ } |
import { FileUtil } from "../util"; | ||
import path from "path"; | ||
/** | ||
@@ -53,3 +54,3 @@ * A step to enrich a template from some subdirectories processing. | ||
else { | ||
subDirs = (await FileUtil.dirNames(baseDir)).map(x => baseDir + "/" + x); | ||
subDirs = (await FileUtil.dirNames(baseDir)).map(x => path.join(baseDir, x)); | ||
} | ||
@@ -56,0 +57,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Jérôme Beau <javarome@gmail.com> (https://javarome.com)", | ||
"version": "1.9.1", | ||
"version": "1.10.0", | ||
"description": "Static Site Generation TypeScript API", | ||
@@ -24,3 +24,3 @@ "exports": "./dist/src/index.js", | ||
"test": "rm -Rf out && tsx src/testAll.ts", | ||
"test-one": "rm -Rf out && tsx src/step/CopyStepTest.ts", | ||
"test-one": "rm -Rf out && tsx src/step/content/replace/html/ssi/SsiEchoVarCommandTest.ts", | ||
"test-ci": "rm -Rf out && tsx src/testAll.ts" | ||
@@ -27,0 +27,0 @@ }, |
@@ -6,6 +6,3 @@ { | ||
"sourceMap": false | ||
}, | ||
"exclude": [ | ||
"test/**/*.*" | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
134970
129
2074