@dosgato/templating 0.0.124 → 0.0.125
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/dist/component.js +2 -2
- package/dist/links.js +15 -6
- package/package.json +1 -1
package/dist/component.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { get, isNotBlank,
|
|
1
|
+
import { get, isNotBlank, titleCase } from 'txstate-utils';
|
|
2
2
|
import { ResourceProvider } from './provider.js';
|
|
3
3
|
function defaultWrap(info) { return info.output; }
|
|
4
4
|
/**
|
|
@@ -286,7 +286,7 @@ export class Page extends Component {
|
|
|
286
286
|
* Get a URL for the current page with a different extension
|
|
287
287
|
*/
|
|
288
288
|
variationUrl(extension) {
|
|
289
|
-
return `${this.url.replace(/\.\w+$/, '')}.${extension}
|
|
289
|
+
return `${this.url.replace(/\.\w+$/, '')}.${extension}`;
|
|
290
290
|
}
|
|
291
291
|
passError(e, path) {
|
|
292
292
|
console.warn(`Recoverable issue occured during render of ${this.pageInfo.path}. Component at ${path} threw the following error:`, e);
|
package/dist/links.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import { htmlDecode } from 'txstate-utils';
|
|
2
|
-
const LinkRegex = /{[^}]*"type"\s?:\s?"\w+"[^}]*}/g;
|
|
3
|
-
const HTMLEscapedLinkRegex = /{[^}]*"type"\s?:\s?"\w+"[^}]*}/g;
|
|
1
|
+
import { htmlDecode, isNotNull } from 'txstate-utils';
|
|
2
|
+
const LinkRegex = /{[^{}]*"type"\s?:\s?"\w+"[^{}]*}/g;
|
|
3
|
+
const HTMLEscapedLinkRegex = /{[^{}]*"type"\s?:\s?"\w+"[^{}]*}/g;
|
|
4
|
+
function safeParse(json) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(json);
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
console.error(e, json);
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
4
13
|
/**
|
|
5
14
|
* This function is used by template definitions to help them identify links inside large blocks
|
|
6
15
|
* of text and return them for indexing, and by render definitions to help replace them with the actual URLs.
|
|
@@ -9,13 +18,13 @@ const HTMLEscapedLinkRegex = /{[^}]*"type"\s?:\s?"\w+"[^}]*}
|
|
|
9
18
|
export function extractLinksFromText(text) {
|
|
10
19
|
if (!text)
|
|
11
20
|
return [];
|
|
12
|
-
const matches = Array.from(text.matchAll(LinkRegex)).map(m =>
|
|
13
|
-
const morematches = Array.from(text.matchAll(HTMLEscapedLinkRegex)).map(m =>
|
|
21
|
+
const matches = Array.from(text.matchAll(LinkRegex)).map(m => safeParse(m[0])).filter(isNotNull);
|
|
22
|
+
const morematches = Array.from(text.matchAll(HTMLEscapedLinkRegex)).map(m => safeParse(htmlDecode(m[0]))).filter(isNotNull);
|
|
14
23
|
return matches.concat(morematches);
|
|
15
24
|
}
|
|
16
25
|
/**
|
|
17
26
|
* This function is used by render definitions to replace `LinkDefinition` conformant link object text in large
|
|
18
27
|
* blocks with the actual URLs they point to at render time. */
|
|
19
28
|
export function replaceLinksInText(text, resolved) {
|
|
20
|
-
return text.replace(LinkRegex, m => resolved.get(m) ?? 'dg-broken-link').replace(HTMLEscapedLinkRegex, m => resolved.get(htmlDecode(m)) ?? 'dg-broken-link');
|
|
29
|
+
return text.replace(LinkRegex, m => resolved.get(m) ?? safeParse(m)?.path ?? 'dg-broken-link').replace(HTMLEscapedLinkRegex, m => resolved.get(htmlDecode(m)) ?? safeParse(htmlDecode(m))?.path ?? 'dg-broken-link');
|
|
21
30
|
}
|