@podlite/publisher 0.0.67 → 0.1.0
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/CHANGELOG.podlite +6 -0
- package/esm/images-plugin.d.ts +5 -0
- package/esm/images-plugin.js +69 -9
- package/esm/images-plugin.js.map +1 -1
- package/esm/state-version-plugin.js +19 -3
- package/esm/state-version-plugin.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/esm/version.js.map +1 -1
- package/lib/images-plugin.d.ts +5 -0
- package/lib/images-plugin.js +71 -10
- package/lib/state-version-plugin.js +19 -3
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.podlite
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
=head1 Upcoming
|
|
4
4
|
|
|
5
|
+
=head1 0.1.0
|
|
6
|
+
|
|
7
|
+
=item a picture with a remote address (C<https:>, C<http:>, any scheme but C<file:>, or C<//>) keeps its address and is not taken for a file to copy; a C<file:> address is read as a URI, from the file of the reference when it has no slash; the version of the site follows the pictures of each record in order, remote and C<data:> addresses included, and no longer stops on an address that names a directory; the module of imports quotes each path whole
|
|
8
|
+
|
|
9
|
+
=item a picture with a C<data:> source is not taken for a file to copy
|
|
10
|
+
|
|
5
11
|
=head1 0.0.65
|
|
6
12
|
|
|
7
13
|
=item files are found with C<glob> 14 instead of the unsupported C<glob> 7. A path that names an existing file is taken as that file, even when the path would also read as a pattern (C<star*.podlite> is the file of that name, not every file it would match), and keeps its spelling, C<./> and C<..> included. A pattern gives files in the old order, keeps its case and a leading C<./> of the pattern itself, and leaves directories and broken links out; what changes for a pattern: a pattern that starts with C<**> once its braces are expanded (C<**/x.podlite>, C<{sub,**}/x.podlite>, not C<{sub/**,ok}/x.podlite>) no longer enters a linked directory, as in a shell; a C<./> inside braces is written out of the paths it gives; POSIX classes and extended patterns are read; C<sub/../> and C<./.> are written out of the paths it gives, and a file it names twice comes once; a directory that cannot be read, met while a pattern is walked, is passed over instead of failing the whole pattern; a pattern whose fixed part goes through such a directory still fails, as before. An empty path is an error, as before. On Node 21, C<glob> 14 warns that it does not list that version
|
package/esm/images-plugin.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { PodliteWebPlugin } from './plugins';
|
|
2
2
|
export declare const readOrientation: (file: string) => number | null;
|
|
3
|
+
export type ImageSource = {
|
|
4
|
+
kind: 'remote' | 'data' | 'local';
|
|
5
|
+
path?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const imageSourceOf: (src: string, from: string) => ImageSource;
|
|
3
8
|
declare const plugin: () => PodliteWebPlugin;
|
|
4
9
|
export default plugin;
|
package/esm/images-plugin.js
CHANGED
|
@@ -2,6 +2,7 @@ import { makeInterator } from '@podlite/schema';
|
|
|
2
2
|
import { ASSETS_PATH, IMAGE_LIB } from './constants.js';
|
|
3
3
|
import pathMod from 'path';
|
|
4
4
|
import * as fs from 'fs';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
5
6
|
import { getPathToOpen } from './node-utils.js';
|
|
6
7
|
import { nodeOrigin } from './source.js';
|
|
7
8
|
const ORIENTATION_TAG = 0x0112;
|
|
@@ -45,29 +46,81 @@ export const readOrientation = (file) => {
|
|
|
45
46
|
}
|
|
46
47
|
return null;
|
|
47
48
|
};
|
|
49
|
+
const isFile = (path) => {
|
|
50
|
+
try {
|
|
51
|
+
return fs.statSync(path).isFile();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
48
57
|
// the build reads the orientation of every image it imports and stops on a value
|
|
49
58
|
// outside 1..8; one such file in a corpus used to cost the whole site
|
|
50
59
|
const isReadable = (file) => {
|
|
51
60
|
const orientation = readOrientation(file);
|
|
52
61
|
return orientation === null || (orientation >= 1 && orientation <= 8);
|
|
53
62
|
};
|
|
63
|
+
/*
|
|
64
|
+
=begin pod :kind<export>
|
|
65
|
+
|
|
66
|
+
=head2 imageSourceOf
|
|
67
|
+
|
|
68
|
+
What the address of a picture names, read from the file it is written in: a
|
|
69
|
+
C<data:> address, a remote one (any scheme of two characters or more but C<file:>,
|
|
70
|
+
or an address that starts with C<//>), or a local file with its path. A C<file:>
|
|
71
|
+
address is a URI: one with a slash is read as a file URL, so C<%20> is a space; one
|
|
72
|
+
without a slash is a path from the file of the reference, decoded where it can be.
|
|
73
|
+
A C<file:> URI that names no local path, as one with a host, is left as written. An
|
|
74
|
+
address with no scheme is a path, as it always was.
|
|
75
|
+
|
|
76
|
+
=end pod
|
|
77
|
+
*/
|
|
78
|
+
export const imageSourceOf = (src, from) => {
|
|
79
|
+
if (/^data:/i.test(src))
|
|
80
|
+
return { kind: 'data' };
|
|
81
|
+
const file = /^file:([\s\S]*)$/i.exec(src);
|
|
82
|
+
if (file) {
|
|
83
|
+
const rest = file[1];
|
|
84
|
+
if (rest.startsWith('/')) {
|
|
85
|
+
try {
|
|
86
|
+
return { kind: 'local', path: fileURLToPath(`file:${rest}`) };
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return { kind: 'remote' };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let decoded = rest;
|
|
93
|
+
try {
|
|
94
|
+
decoded = decodeURIComponent(rest);
|
|
95
|
+
}
|
|
96
|
+
catch { }
|
|
97
|
+
return { kind: 'local', path: pathMod.normalize(pathMod.join(pathMod.dirname(from), decoded)) };
|
|
98
|
+
}
|
|
99
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]+:/.test(src) || src.startsWith('//'))
|
|
100
|
+
return { kind: 'remote' };
|
|
101
|
+
return { kind: 'local', path: getPathToOpen(src, from).path };
|
|
102
|
+
};
|
|
54
103
|
const plugin = () => {
|
|
55
104
|
const outCtx = {};
|
|
56
105
|
const imagesMap = new Map();
|
|
106
|
+
// every picture of every record in order, repeats too, for the version of the site;
|
|
107
|
+
// a record is the page it publishes, as one file may give several notes
|
|
108
|
+
const imageSources = [];
|
|
57
109
|
const onExit = ctx => {
|
|
58
110
|
if (!ctx.testing) {
|
|
59
111
|
// process Images
|
|
60
112
|
let libFileContent = '';
|
|
61
113
|
for (const key of imagesMap.keys()) {
|
|
62
114
|
const variable_name = imagesMap.get(key);
|
|
63
|
-
|
|
115
|
+
// only a file is imported: a path that names a directory, as file:/// does, is not
|
|
116
|
+
if (!isFile(key)) {
|
|
64
117
|
continue;
|
|
65
118
|
}
|
|
66
119
|
if (!isReadable(key)) {
|
|
67
120
|
console.warn(`image skipped, its orientation is not a value the build can read: ${key}`);
|
|
68
121
|
continue;
|
|
69
122
|
}
|
|
70
|
-
libFileContent += `import ${variable_name} from
|
|
123
|
+
libFileContent += `import ${variable_name} from ${JSON.stringify(key)}
|
|
71
124
|
export { ${variable_name} }
|
|
72
125
|
`;
|
|
73
126
|
}
|
|
@@ -76,15 +129,21 @@ export default {}
|
|
|
76
129
|
`;
|
|
77
130
|
fs.writeFileSync(IMAGE_LIB, libFileContent, 'utf8');
|
|
78
131
|
}
|
|
79
|
-
return { ...ctx, ...outCtx, ...{ imagesMap: Object.fromEntries(imagesMap) } };
|
|
132
|
+
return { ...ctx, ...outCtx, ...{ imagesMap: Object.fromEntries(imagesMap), imageSources } };
|
|
80
133
|
};
|
|
81
|
-
const processNode = (node, file) => {
|
|
134
|
+
const processNode = (node, file, record) => {
|
|
82
135
|
const rules = {
|
|
83
136
|
':image': node => {
|
|
84
|
-
|
|
85
|
-
|
|
137
|
+
if (typeof node.src !== 'string')
|
|
138
|
+
return node;
|
|
86
139
|
// a picture an include brought is found from the file it was written in
|
|
87
|
-
const
|
|
140
|
+
const source = imageSourceOf(node.src, nodeOrigin(node)?.file ?? file);
|
|
141
|
+
const address = source.path ?? node.src;
|
|
142
|
+
imageSources.push({ file: record, kind: source.kind, address });
|
|
143
|
+
// a data: or remote address is no file to copy
|
|
144
|
+
if (source.kind !== 'local')
|
|
145
|
+
return node;
|
|
146
|
+
const path = address;
|
|
88
147
|
const { name, ext, dir } = pathMod.parse(path);
|
|
89
148
|
const variable_name = 'i' + path.split('/').slice(1).join('_').replace(/\W+/g, '_').toLowerCase();
|
|
90
149
|
const newFileName = `${variable_name}${ext}`;
|
|
@@ -97,11 +156,12 @@ export default {}
|
|
|
97
156
|
};
|
|
98
157
|
const onProcess = (recs) => {
|
|
99
158
|
const res = recs.map(item => {
|
|
100
|
-
const
|
|
159
|
+
const record = item.publishUrl ?? item.file;
|
|
160
|
+
const node = processNode(item.node, item.file, record);
|
|
101
161
|
// process images inside description
|
|
102
162
|
let extra = {};
|
|
103
163
|
if (item.description) {
|
|
104
|
-
extra.description = processNode(item.description, item.file);
|
|
164
|
+
extra.description = processNode(item.description, item.file, record);
|
|
105
165
|
}
|
|
106
166
|
return { ...item, node, ...extra };
|
|
107
167
|
});
|
package/esm/images-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"images-plugin.js","sourceRoot":"","sources":["../src/images-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAW,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,OAAO,MAAM,MAAM,CAAA;AAC1B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAG5C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,MAAM,eAAe,GAAG,MAAM,CAAA;AAE9B,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAiB,EAAE;IAC7D,IAAI,KAAa,CAAA;IACjB,IAAI,CAAC;QACH,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,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AAO,GAAG,CAAA;IACZ,CAAC,CAAA;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AAC5B,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -17,8 +17,24 @@ const plugin = (appVersion, indexFilePath) => {
|
|
|
17
17
|
return prev + CRC32.str(getTextContentFromNode(current.node));
|
|
18
18
|
}, '');
|
|
19
19
|
};
|
|
20
|
+
const isFile = (path) => {
|
|
21
|
+
try {
|
|
22
|
+
return fs.statSync(path).isFile();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// the pictures of each record in order, as the images plugin read them; without
|
|
29
|
+
// it, the files it found
|
|
30
|
+
const getImagesVersion = (ctx) => Array.isArray(ctx.imageSources)
|
|
31
|
+
? ctx.imageSources
|
|
32
|
+
.map(({ file, kind, address }) => `${CRC32.str(`${file}\u0000${kind}\u0000${address}`)}` +
|
|
33
|
+
(kind === 'local' && isFile(address) ? `${CRC32.buf(new Uint8Array(fs.readFileSync(address)))}` : ''))
|
|
34
|
+
.join('')
|
|
35
|
+
: '';
|
|
20
36
|
const getAssetPaths = (ctx) => {
|
|
21
|
-
const paths = Object.keys(ctx.imagesMap || {});
|
|
37
|
+
const paths = Array.isArray(ctx.imageSources) ? [] : Object.keys(ctx.imagesMap || {});
|
|
22
38
|
const indexPage = indexFilePath ? records.find(item => item.file === indexFilePath) : undefined;
|
|
23
39
|
if (indexPage) {
|
|
24
40
|
const [pod] = getFromTree(indexPage.node, 'pod');
|
|
@@ -36,8 +52,8 @@ const plugin = (appVersion, indexFilePath) => {
|
|
|
36
52
|
const getAssetsVersion = (ctx) => {
|
|
37
53
|
return getAssetPaths(ctx).reduce((prev, path) => {
|
|
38
54
|
// a missing file contributes its path, so adding the file later moves the sum
|
|
39
|
-
return prev + (
|
|
40
|
-
},
|
|
55
|
+
return prev + (isFile(path) ? CRC32.buf(new Uint8Array(fs.readFileSync(path))) : CRC32.str(path));
|
|
56
|
+
}, getImagesVersion(ctx));
|
|
41
57
|
};
|
|
42
58
|
const onProcess = (recs) => {
|
|
43
59
|
crc_sum += getStateVersion(recs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-version-plugin.js","sourceRoot":"","sources":["../src/state-version-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAA;AAC/B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,MAAM,MAAM,MAAM,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAGhF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,MAAM,MAAM,GAAG,CAAC,UAAmB,EAAE,aAAsB,EAAoB,EAAE;IAC/E,MAAM,MAAM,GAA4B,EAAE,CAAA;IAC1C,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,MAAM,OAAO,GAAoB,EAAE,CAAA;IACnC,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE;QACnB,MAAM,CAAC,YAAY;YACjB,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,OAAO,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QACvG,OAAO,EAAE,GAAG,GAAG,EAAE,GAAG,MAAM,EAAE,CAAA;IAC9B,CAAC,CAAA;IACD,MAAM,eAAe,GAAG,CAAC,UAAU,EAAU,EAAE;QAC7C,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE;YACzC,OAAO,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;QAC/D,CAAC,EAAE,EAA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IAAI,CAAC,CAAA;QACrB,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;AAC5B,CAAC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.0
|
|
1
|
+
export declare const version = "0.1.0";
|
package/esm/version.js
CHANGED
package/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
|
package/lib/images-plugin.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { PodliteWebPlugin } from './plugins';
|
|
2
2
|
export declare const readOrientation: (file: string) => number | null;
|
|
3
|
+
export type ImageSource = {
|
|
4
|
+
kind: 'remote' | 'data' | 'local';
|
|
5
|
+
path?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const imageSourceOf: (src: string, from: string) => ImageSource;
|
|
3
8
|
declare const plugin: () => PodliteWebPlugin;
|
|
4
9
|
export default plugin;
|
package/lib/images-plugin.js
CHANGED
|
@@ -36,11 +36,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.readOrientation = void 0;
|
|
39
|
+
exports.imageSourceOf = exports.readOrientation = void 0;
|
|
40
40
|
const schema_1 = require("@podlite/schema");
|
|
41
41
|
const constants_1 = require("./constants");
|
|
42
42
|
const path_1 = __importDefault(require("path"));
|
|
43
43
|
const fs = __importStar(require("fs"));
|
|
44
|
+
const url_1 = require("url");
|
|
44
45
|
const node_utils_1 = require("./node-utils");
|
|
45
46
|
const source_1 = require("./source");
|
|
46
47
|
const ORIENTATION_TAG = 0x0112;
|
|
@@ -85,29 +86,82 @@ const readOrientation = (file) => {
|
|
|
85
86
|
return null;
|
|
86
87
|
};
|
|
87
88
|
exports.readOrientation = readOrientation;
|
|
89
|
+
const isFile = (path) => {
|
|
90
|
+
try {
|
|
91
|
+
return fs.statSync(path).isFile();
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
88
97
|
// the build reads the orientation of every image it imports and stops on a value
|
|
89
98
|
// outside 1..8; one such file in a corpus used to cost the whole site
|
|
90
99
|
const isReadable = (file) => {
|
|
91
100
|
const orientation = (0, exports.readOrientation)(file);
|
|
92
101
|
return orientation === null || (orientation >= 1 && orientation <= 8);
|
|
93
102
|
};
|
|
103
|
+
/*
|
|
104
|
+
=begin pod :kind<export>
|
|
105
|
+
|
|
106
|
+
=head2 imageSourceOf
|
|
107
|
+
|
|
108
|
+
What the address of a picture names, read from the file it is written in: a
|
|
109
|
+
C<data:> address, a remote one (any scheme of two characters or more but C<file:>,
|
|
110
|
+
or an address that starts with C<//>), or a local file with its path. A C<file:>
|
|
111
|
+
address is a URI: one with a slash is read as a file URL, so C<%20> is a space; one
|
|
112
|
+
without a slash is a path from the file of the reference, decoded where it can be.
|
|
113
|
+
A C<file:> URI that names no local path, as one with a host, is left as written. An
|
|
114
|
+
address with no scheme is a path, as it always was.
|
|
115
|
+
|
|
116
|
+
=end pod
|
|
117
|
+
*/
|
|
118
|
+
const imageSourceOf = (src, from) => {
|
|
119
|
+
if (/^data:/i.test(src))
|
|
120
|
+
return { kind: 'data' };
|
|
121
|
+
const file = /^file:([\s\S]*)$/i.exec(src);
|
|
122
|
+
if (file) {
|
|
123
|
+
const rest = file[1];
|
|
124
|
+
if (rest.startsWith('/')) {
|
|
125
|
+
try {
|
|
126
|
+
return { kind: 'local', path: (0, url_1.fileURLToPath)(`file:${rest}`) };
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return { kind: 'remote' };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
let decoded = rest;
|
|
133
|
+
try {
|
|
134
|
+
decoded = decodeURIComponent(rest);
|
|
135
|
+
}
|
|
136
|
+
catch { }
|
|
137
|
+
return { kind: 'local', path: path_1.default.normalize(path_1.default.join(path_1.default.dirname(from), decoded)) };
|
|
138
|
+
}
|
|
139
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]+:/.test(src) || src.startsWith('//'))
|
|
140
|
+
return { kind: 'remote' };
|
|
141
|
+
return { kind: 'local', path: (0, node_utils_1.getPathToOpen)(src, from).path };
|
|
142
|
+
};
|
|
143
|
+
exports.imageSourceOf = imageSourceOf;
|
|
94
144
|
const plugin = () => {
|
|
95
145
|
const outCtx = {};
|
|
96
146
|
const imagesMap = new Map();
|
|
147
|
+
// every picture of every record in order, repeats too, for the version of the site;
|
|
148
|
+
// a record is the page it publishes, as one file may give several notes
|
|
149
|
+
const imageSources = [];
|
|
97
150
|
const onExit = ctx => {
|
|
98
151
|
if (!ctx.testing) {
|
|
99
152
|
// process Images
|
|
100
153
|
let libFileContent = '';
|
|
101
154
|
for (const key of imagesMap.keys()) {
|
|
102
155
|
const variable_name = imagesMap.get(key);
|
|
103
|
-
|
|
156
|
+
// only a file is imported: a path that names a directory, as file:/// does, is not
|
|
157
|
+
if (!isFile(key)) {
|
|
104
158
|
continue;
|
|
105
159
|
}
|
|
106
160
|
if (!isReadable(key)) {
|
|
107
161
|
console.warn(`image skipped, its orientation is not a value the build can read: ${key}`);
|
|
108
162
|
continue;
|
|
109
163
|
}
|
|
110
|
-
libFileContent += `import ${variable_name} from
|
|
164
|
+
libFileContent += `import ${variable_name} from ${JSON.stringify(key)}
|
|
111
165
|
export { ${variable_name} }
|
|
112
166
|
`;
|
|
113
167
|
}
|
|
@@ -116,15 +170,21 @@ export default {}
|
|
|
116
170
|
`;
|
|
117
171
|
fs.writeFileSync(constants_1.IMAGE_LIB, libFileContent, 'utf8');
|
|
118
172
|
}
|
|
119
|
-
return { ...ctx, ...outCtx, ...{ imagesMap: Object.fromEntries(imagesMap) } };
|
|
173
|
+
return { ...ctx, ...outCtx, ...{ imagesMap: Object.fromEntries(imagesMap), imageSources } };
|
|
120
174
|
};
|
|
121
|
-
const processNode = (node, file) => {
|
|
175
|
+
const processNode = (node, file, record) => {
|
|
122
176
|
const rules = {
|
|
123
177
|
':image': node => {
|
|
124
|
-
|
|
125
|
-
|
|
178
|
+
if (typeof node.src !== 'string')
|
|
179
|
+
return node;
|
|
126
180
|
// a picture an include brought is found from the file it was written in
|
|
127
|
-
const
|
|
181
|
+
const source = (0, exports.imageSourceOf)(node.src, (0, source_1.nodeOrigin)(node)?.file ?? file);
|
|
182
|
+
const address = source.path ?? node.src;
|
|
183
|
+
imageSources.push({ file: record, kind: source.kind, address });
|
|
184
|
+
// a data: or remote address is no file to copy
|
|
185
|
+
if (source.kind !== 'local')
|
|
186
|
+
return node;
|
|
187
|
+
const path = address;
|
|
128
188
|
const { name, ext, dir } = path_1.default.parse(path);
|
|
129
189
|
const variable_name = 'i' + path.split('/').slice(1).join('_').replace(/\W+/g, '_').toLowerCase();
|
|
130
190
|
const newFileName = `${variable_name}${ext}`;
|
|
@@ -137,11 +197,12 @@ export default {}
|
|
|
137
197
|
};
|
|
138
198
|
const onProcess = (recs) => {
|
|
139
199
|
const res = recs.map(item => {
|
|
140
|
-
const
|
|
200
|
+
const record = item.publishUrl ?? item.file;
|
|
201
|
+
const node = processNode(item.node, item.file, record);
|
|
141
202
|
// process images inside description
|
|
142
203
|
let extra = {};
|
|
143
204
|
if (item.description) {
|
|
144
|
-
extra.description = processNode(item.description, item.file);
|
|
205
|
+
extra.description = processNode(item.description, item.file, record);
|
|
145
206
|
}
|
|
146
207
|
return { ...item, node, ...extra };
|
|
147
208
|
});
|
|
@@ -55,8 +55,24 @@ const plugin = (appVersion, indexFilePath) => {
|
|
|
55
55
|
return prev + CRC32.str((0, schema_1.getTextContentFromNode)(current.node));
|
|
56
56
|
}, '');
|
|
57
57
|
};
|
|
58
|
+
const isFile = (path) => {
|
|
59
|
+
try {
|
|
60
|
+
return fs.statSync(path).isFile();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
// the pictures of each record in order, as the images plugin read them; without
|
|
67
|
+
// it, the files it found
|
|
68
|
+
const getImagesVersion = (ctx) => Array.isArray(ctx.imageSources)
|
|
69
|
+
? ctx.imageSources
|
|
70
|
+
.map(({ file, kind, address }) => `${CRC32.str(`${file}\u0000${kind}\u0000${address}`)}` +
|
|
71
|
+
(kind === 'local' && isFile(address) ? `${CRC32.buf(new Uint8Array(fs.readFileSync(address)))}` : ''))
|
|
72
|
+
.join('')
|
|
73
|
+
: '';
|
|
58
74
|
const getAssetPaths = (ctx) => {
|
|
59
|
-
const paths = Object.keys(ctx.imagesMap || {});
|
|
75
|
+
const paths = Array.isArray(ctx.imageSources) ? [] : Object.keys(ctx.imagesMap || {});
|
|
60
76
|
const indexPage = indexFilePath ? records.find(item => item.file === indexFilePath) : undefined;
|
|
61
77
|
if (indexPage) {
|
|
62
78
|
const [pod] = (0, schema_1.getFromTree)(indexPage.node, 'pod');
|
|
@@ -74,8 +90,8 @@ const plugin = (appVersion, indexFilePath) => {
|
|
|
74
90
|
const getAssetsVersion = (ctx) => {
|
|
75
91
|
return getAssetPaths(ctx).reduce((prev, path) => {
|
|
76
92
|
// a missing file contributes its path, so adding the file later moves the sum
|
|
77
|
-
return prev + (
|
|
78
|
-
},
|
|
93
|
+
return prev + (isFile(path) ? CRC32.buf(new Uint8Array(fs.readFileSync(path))) : CRC32.str(path));
|
|
94
|
+
}, getImagesVersion(ctx));
|
|
79
95
|
};
|
|
80
96
|
const onProcess = (recs) => {
|
|
81
97
|
crc_sum += getStateVersion(recs);
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.0
|
|
1
|
+
export declare const version = "0.1.0";
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@podlite/publisher",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Publishing toolkit for Podlite — transform documents to HTML, generate sites",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -84,13 +84,13 @@
|
|
|
84
84
|
"transform"
|
|
85
85
|
],
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@podlite/markdown": "0.0
|
|
88
|
-
"@podlite/schema": "0.0
|
|
87
|
+
"@podlite/markdown": "0.1.0",
|
|
88
|
+
"@podlite/schema": "0.1.0",
|
|
89
89
|
"crc-32": "^1.2.2",
|
|
90
90
|
"glob": "^14.0.4",
|
|
91
91
|
"gray-matter": "^4.0.3",
|
|
92
92
|
"js-yaml": "^3.15.2",
|
|
93
|
-
"podlite": "0.0
|
|
93
|
+
"podlite": "0.1.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@types/node": "^17.0.7",
|