@dosgato/templating 0.0.124 → 0.0.126
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/apitemplate.d.ts +2 -2
- package/dist/component.d.ts +1 -1
- package/dist/component.js +2 -2
- package/dist/links.js +15 -6
- package/dist/provider.js +2 -1
- package/dist/render.d.ts +22 -6
- package/dist/uitemplate.d.ts +1 -1
- package/package.json +3 -3
package/dist/apitemplate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentData, DataData, PageData } from './component.js';
|
|
2
|
-
import { LinkDefinition } from './links.js';
|
|
1
|
+
import type { ComponentData, DataData, PageData } from './component.js';
|
|
2
|
+
import { type LinkDefinition } from './links.js';
|
|
3
3
|
export type APITemplateType = 'page' | 'component' | 'data';
|
|
4
4
|
export declare enum ValidationMessageType {
|
|
5
5
|
ERROR = "error",
|
package/dist/component.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { IncomingHttpHeaders } from 'http';
|
|
4
4
|
import type { ParsedUrlQuery } from 'querystring';
|
|
5
5
|
import { ResourceProvider } from './provider.js';
|
|
6
|
-
import { APIClient } from './render.js';
|
|
6
|
+
import { type APIClient } from './render.js';
|
|
7
7
|
/**
|
|
8
8
|
* This is the primary templating class to build your templates. Subclass it and provide
|
|
9
9
|
* at least a render function.
|
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
|
}
|
package/dist/provider.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* If you do this, don't forget to register the provider along with your templates!
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
class ResourceProvider {
|
|
12
12
|
static webpath(name) { return this.webpaths.get(name); }
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
@@ -86,3 +86,4 @@ ResourceProvider.files = new Map();
|
|
|
86
86
|
* `<img src="${TemplateClass.webpath('keyname')}">`
|
|
87
87
|
*/
|
|
88
88
|
ResourceProvider.webpaths = new Map();
|
|
89
|
+
export { ResourceProvider };
|
package/dist/render.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ContextBase, DataData, PageData, PageRecord, PageRecordOptionalData } from './component.js';
|
|
2
|
-
import { AssetFolderLink, AssetLink, DataFolderLink, DataLink, LinkDefinition, PageLink } from './links.js';
|
|
1
|
+
import type { ContextBase, DataData, PageData, PageRecord, PageRecordOptionalData } from './component.js';
|
|
2
|
+
import type { AssetFolderLink, AssetLink, DataFolderLink, DataLink, LinkDefinition, PageLink } from './links.js';
|
|
3
3
|
/**
|
|
4
4
|
* Safely encapsulates `content` in header tags based on the `ctx` context passed and adds any passed `attributes` to the header tagging.
|
|
5
5
|
* If the headerLevel passed through `ctx` is outside the range of 1..6 the header tag generated is normalized to the nearest value of 1 or 6.
|
|
@@ -52,6 +52,14 @@ export interface AssetRecord {
|
|
|
52
52
|
downloadLink: string;
|
|
53
53
|
image?: PictureAttributes;
|
|
54
54
|
}
|
|
55
|
+
export interface DataRecord {
|
|
56
|
+
id: string;
|
|
57
|
+
path: string;
|
|
58
|
+
name: string;
|
|
59
|
+
modifiedAt?: Date;
|
|
60
|
+
publishedAt?: Date;
|
|
61
|
+
data: DataData;
|
|
62
|
+
}
|
|
55
63
|
export interface PageForNavigation {
|
|
56
64
|
id: string;
|
|
57
65
|
name: string;
|
|
@@ -249,14 +257,22 @@ export interface APIClient {
|
|
|
249
257
|
* Get data entries by link or folder link
|
|
250
258
|
*
|
|
251
259
|
* Returns an array in case link is a DataFolderLink. If link is a DataLink, will return an
|
|
252
|
-
* array with length <= 1.
|
|
260
|
+
* array with length <= 1. If link is a DataFolderLink to a DataRoot, returns all descendant data
|
|
261
|
+
* recursively.
|
|
262
|
+
*
|
|
263
|
+
* Never returns deleted or unpublished data, and only returns the published version
|
|
264
|
+
* of a piece of data, even in edit mode.
|
|
253
265
|
*/
|
|
254
|
-
getDataByLink: (link: string | DataLink | DataFolderLink) => Promise<
|
|
266
|
+
getDataByLink: (link: string | DataLink | DataFolderLink) => Promise<DataRecord[]>;
|
|
255
267
|
/**
|
|
256
268
|
* Get data entries by full path including site
|
|
257
269
|
*
|
|
258
270
|
* Use '/global' for global data. If path refers to a specific data item, will return
|
|
259
|
-
* an array with length <= 1.
|
|
271
|
+
* an array with length <= 1. If path refers to a DataRoot, returns all descendant
|
|
272
|
+
* data recursively.
|
|
273
|
+
*
|
|
274
|
+
* Never returns deleted or unpublished data, and only returns the published version
|
|
275
|
+
* of a piece of data, even in edit mode.
|
|
260
276
|
*/
|
|
261
|
-
getDataByPath: (templateKey: string, path: string) => Promise<
|
|
277
|
+
getDataByPath: (templateKey: string, path: string) => Promise<DataRecord[]>;
|
|
262
278
|
}
|
package/dist/uitemplate.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dosgato/templating",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"description": "A library to support building templates for dosgato CMS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "^18.7.11",
|
|
21
|
-
"eslint-config-standard-with-typescript": "^
|
|
22
|
-
"typescript": "^
|
|
21
|
+
"eslint-config-standard-with-typescript": "^34.0.0",
|
|
22
|
+
"typescript": "^5.0.4"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|