@podlite/publisher 0.0.51 → 0.0.53

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.
Files changed (55) hide show
  1. package/CHANGELOG.podlite +40 -0
  2. package/esm/catalogue.d.ts +17 -0
  3. package/esm/catalogue.js +156 -0
  4. package/esm/catalogue.js.map +1 -0
  5. package/esm/images-plugin.js +3 -1
  6. package/esm/images-plugin.js.map +1 -1
  7. package/esm/include-resolve-plugin.d.ts +16 -1
  8. package/esm/include-resolve-plugin.js +238 -50
  9. package/esm/include-resolve-plugin.js.map +1 -1
  10. package/esm/links-plugin.d.ts +9 -1
  11. package/esm/links-plugin.js +144 -58
  12. package/esm/links-plugin.js.map +1 -1
  13. package/esm/node-utils.d.ts +5 -3
  14. package/esm/node-utils.js +81 -24
  15. package/esm/node-utils.js.map +1 -1
  16. package/esm/pubdate-plugin.js +7 -5
  17. package/esm/pubdate-plugin.js.map +1 -1
  18. package/esm/react-plugin.js +9 -1
  19. package/esm/react-plugin.js.map +1 -1
  20. package/esm/reading.d.ts +5 -0
  21. package/esm/reading.js +34 -0
  22. package/esm/reading.js.map +1 -0
  23. package/esm/record.d.ts +2 -0
  24. package/esm/record.js +1 -0
  25. package/esm/record.js.map +1 -1
  26. package/esm/site-data-plugin.d.ts +1 -0
  27. package/esm/site-data-plugin.js +12 -1
  28. package/esm/site-data-plugin.js.map +1 -1
  29. package/esm/source.d.ts +19 -0
  30. package/esm/source.js +85 -0
  31. package/esm/source.js.map +1 -0
  32. package/esm/version.d.ts +1 -1
  33. package/esm/version.js +1 -1
  34. package/lib/catalogue.d.ts +17 -0
  35. package/lib/catalogue.js +197 -0
  36. package/lib/images-plugin.js +3 -1
  37. package/lib/include-resolve-plugin.d.ts +16 -1
  38. package/lib/include-resolve-plugin.js +273 -49
  39. package/lib/links-plugin.d.ts +9 -1
  40. package/lib/links-plugin.js +177 -56
  41. package/lib/node-utils.d.ts +5 -3
  42. package/lib/node-utils.js +96 -37
  43. package/lib/pubdate-plugin.js +7 -5
  44. package/lib/react-plugin.js +9 -1
  45. package/lib/reading.d.ts +5 -0
  46. package/lib/reading.js +38 -0
  47. package/lib/record.d.ts +2 -0
  48. package/lib/record.js +6 -1
  49. package/lib/site-data-plugin.d.ts +1 -0
  50. package/lib/site-data-plugin.js +13 -1
  51. package/lib/source.d.ts +19 -0
  52. package/lib/source.js +94 -0
  53. package/lib/version.d.ts +1 -1
  54. package/lib/version.js +1 -1
  55. package/package.json +4 -4
package/lib/node-utils.js CHANGED
@@ -36,9 +36,10 @@ 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.convertFileLinksToUrl = exports.makeLinksMap = exports.getPathToOpen = void 0;
39
+ exports.PARSER_TYPES = exports.convertFileLinksToUrl = exports.makeLinksMap = exports.isIndexed = exports.getPathToOpen = void 0;
40
40
  exports.parseFiles = parseFiles;
41
41
  exports.getParserTypeforFile = getParserTypeforFile;
42
+ exports.parseText = parseText;
42
43
  exports.parseFile = parseFile;
43
44
  exports.getDocumentAttributes = getDocumentAttributes;
44
45
  exports.getPublishAttributes = getPublishAttributes;
@@ -52,8 +53,9 @@ const path_1 = __importDefault(require("path"));
52
53
  const glob_1 = __importDefault(require("glob"));
53
54
  const shared_1 = require("./shared");
54
55
  const markdown_1 = require("@podlite/markdown");
55
- const podlite_1 = require("podlite");
56
56
  const gray_matter_1 = __importDefault(require("gray-matter"));
57
+ const source_1 = require("./source");
58
+ const reading_1 = require("./reading");
57
59
  const getPathToOpen = (filepath, parentDocPath) => {
58
60
  const isRemoteReg = new RegExp(/^(https?|ftp):/);
59
61
  const isRemote = isRemoteReg.test(filepath);
@@ -67,10 +69,46 @@ const getPathToOpen = (filepath, parentDocPath) => {
67
69
  };
68
70
  };
69
71
  exports.getPathToOpen = getPathToOpen;
72
+ /*
73
+ =begin pod :kind<export>
74
+
75
+ =head2 isIndexed
76
+
77
+ Whether a search engine is told to index the record: its first C<pod> block
78
+ carries no C<:noindex>. A record without a C<pod> block is indexed.
79
+
80
+ =end pod
81
+ */
82
+ const isIndexed = (record) => {
83
+ const [pod] = (0, schema_1.getFromTree)(record.node, 'pod');
84
+ return !pod || !(0, schema_1.makeAttrs)(pod, {}).getFirstValue('noindex');
85
+ };
86
+ exports.isIndexed = isIndexed;
87
+ /*
88
+ =begin pod :kind<export>
89
+
90
+ =head2 makeLinksMap
91
+
92
+ The address of each file, by its path. A file placed at more than one address
93
+ gives the address of the last record a search engine is told to index, and of the
94
+ last record when none or all of them are: the current version of a document and
95
+ its permanent address, kept out of the index, give the first.
96
+
97
+ =end pod
98
+ */
70
99
  const makeLinksMap = (records) => {
71
- const linksMap = {
72
- ...Object.fromEntries(records.map(({ publishUrl = '', file }) => [(0, exports.getPathToOpen)(file, './').path, publishUrl])),
73
- };
100
+ const linksMap = {};
101
+ const indexed = {};
102
+ for (const record of records) {
103
+ // by the absolute path: a link an include brought is found from the absolute path of its file
104
+ const key = path_1.default.resolve((0, exports.getPathToOpen)(record.file, './').path);
105
+ const own = (0, exports.isIndexed)(record);
106
+ if (key in linksMap && indexed[key] && !own)
107
+ continue;
108
+ const { publishUrl = '' } = record;
109
+ linksMap[key] = publishUrl;
110
+ indexed[key] = own;
111
+ }
74
112
  return linksMap;
75
113
  };
76
114
  exports.makeLinksMap = makeLinksMap;
@@ -83,8 +121,9 @@ const convertFileLinksToUrl = (records, additinalMap = {}) => {
83
121
  const link = meta ? meta : (0, schema_1.getTextContentFromNode)(content);
84
122
  const r = link.match(/file:\s*(?<path>(.+))\s*$/);
85
123
  const convertFileToUrl = filePath => {
86
- const { isRemote, path } = (0, exports.getPathToOpen)(filePath, item.file);
87
- return isRemote ? null : linksMap[path];
124
+ // a link an include brought is found from the file it was written in
125
+ const { isRemote, path: target } = (0, exports.getPathToOpen)(filePath, (0, source_1.nodeOrigin)(node)?.file ?? item.file);
126
+ return isRemote ? null : linksMap[path_1.default.resolve(target)];
88
127
  };
89
128
  const newLink = r?.groups?.path ? convertFileToUrl(r.groups.path) : link;
90
129
  const newContent = {
@@ -174,7 +213,17 @@ function parseFiles(path) {
174
213
  .filter(Boolean);
175
214
  return allFiles;
176
215
  }
177
- const PARSER_TYPES = {
216
+ /*
217
+ =begin pod :kind<export>
218
+
219
+ =head2 PARSER_TYPES
220
+
221
+ The readings a file can be given by its name or its declared type:
222
+ C<getParserTypeforFile> answers with one of them.
223
+
224
+ =end pod
225
+ */
226
+ exports.PARSER_TYPES = {
178
227
  MARKDOWN: 'markdown',
179
228
  PODLITE: 'podlite',
180
229
  DEFAULT: 'default',
@@ -187,10 +236,10 @@ const MIME_TYPES_EXTENSIONS = {
187
236
  'audio/mpeg': ['.mp3'],
188
237
  };
189
238
  const PARSER_TYPE_MIME_TYPES = {
190
- [PARSER_TYPES.PODLITE]: ['text/podlite'],
191
- [PARSER_TYPES.MARKDOWN]: ['text/markdown'],
192
- [PARSER_TYPES.DEFAULT]: ['text/plain'],
193
- [PARSER_TYPES.ERROR]: ['audio/mpeg'],
239
+ [exports.PARSER_TYPES.PODLITE]: ['text/podlite'],
240
+ [exports.PARSER_TYPES.MARKDOWN]: ['text/markdown'],
241
+ [exports.PARSER_TYPES.DEFAULT]: ['text/plain'],
242
+ [exports.PARSER_TYPES.ERROR]: ['audio/mpeg'],
194
243
  };
195
244
  function getParserTypeforFile(filePath, mime) {
196
245
  // get parser type using PARSER_TYPE_MIME_TYPES
@@ -202,40 +251,48 @@ function getParserTypeforFile(filePath, mime) {
202
251
  }
203
252
  // if not found return default TODO: possible change to error
204
253
  console.warn(`Mime type ${mime} not found, using default parser`);
205
- return PARSER_TYPES.DEFAULT;
254
+ return exports.PARSER_TYPES.DEFAULT;
206
255
  }
207
256
  const ext = path_1.default.extname(filePath).toLowerCase();
208
257
  const parserTypeMap = {
209
- '.md': PARSER_TYPES.MARKDOWN,
210
- '.markdown': PARSER_TYPES.MARKDOWN,
211
- '.podlite': PARSER_TYPES.PODLITE,
212
- '.rakudoc': PARSER_TYPES.PODLITE,
213
- '.pod6': PARSER_TYPES.PODLITE,
258
+ '.md': exports.PARSER_TYPES.MARKDOWN,
259
+ '.markdown': exports.PARSER_TYPES.MARKDOWN,
260
+ '.podlite': exports.PARSER_TYPES.PODLITE,
261
+ '.rakudoc': exports.PARSER_TYPES.PODLITE,
262
+ '.pod6': exports.PARSER_TYPES.PODLITE,
214
263
  };
215
- return parserTypeMap[ext] || PARSER_TYPES.DEFAULT;
264
+ return parserTypeMap[ext] || exports.PARSER_TYPES.DEFAULT;
216
265
  }
217
- function parseFile(filePath, fileContent, mime) {
266
+ /*
267
+ =begin pod :kind<export>
268
+
269
+ =head2 parseText
270
+
271
+ Parses a text the way a file of that name is read: the type comes from C<mime>,
272
+ else from the extension. The text is taken as given, an empty one included, and
273
+ nothing is read from disk.
274
+
275
+ =end pod
276
+ */
277
+ // the reader gives a list of nodes only for Markdown, which is read apart here
278
+ const asDocument = (tree) => Array.isArray(tree) ? (0, schema_1.mkRootBlock)({}, tree) : tree;
279
+ function parseText(filePath, text, mime) {
218
280
  // check extension of file and parse it deepnds on mime type
219
281
  const parser_type = getParserTypeforFile(filePath, mime);
282
+ // the reader an include reads the texts it brings with, the body of =React read in its place
220
283
  const typeToParserMap = {
221
- [PARSER_TYPES.PODLITE]: (src) => {
222
- const podlite_processor = (0, podlite_1.podlite)({ importPlugins: true }).use({});
223
- const tree = podlite_processor.parse(src, { skipChain: 0, podMode: 1 });
224
- return podlite_processor.toAstResult(tree).interator;
225
- },
284
+ [exports.PARSER_TYPES.PODLITE]: (src) => asDocument((0, reading_1.readRecordText)(src, filePath, undefined, { format: 'podlite' })),
226
285
  //@ts-ignore TODO: fix this
227
- [PARSER_TYPES.MARKDOWN]: (src) => {
286
+ [exports.PARSER_TYPES.MARKDOWN]: (src) => {
228
287
  const { content } = (0, gray_matter_1.default)(src);
229
288
  return (0, markdown_1.parseMd)(content);
230
289
  },
231
- [PARSER_TYPES.DEFAULT]: (src) => {
232
- const podlite_processor = (0, podlite_1.podlite)({ importPlugins: true }).use({});
233
- const tree = podlite_processor.parse(src, { skipChain: 0, podMode: 0 });
234
- return podlite_processor.toAstResult(tree).interator;
235
- },
290
+ [exports.PARSER_TYPES.DEFAULT]: (src) => asDocument((0, reading_1.readRecordText)(src, filePath, undefined, { format: 'default' })),
236
291
  };
237
- const src = fileContent || fs.readFileSync(filePath).toString();
238
- return typeToParserMap[parser_type](src);
292
+ return typeToParserMap[parser_type](text);
293
+ }
294
+ function parseFile(filePath, fileContent, mime) {
295
+ return parseText(filePath, fileContent || fs.readFileSync(filePath).toString(), mime);
239
296
  }
240
297
  // An address written without quotes is cut into a list at every space, and only
241
298
  // its first word reaches the page. The page then lands on a short address, or on
@@ -370,13 +427,14 @@ function getPublishAttributes(node, filePath) {
370
427
  return props;
371
428
  }
372
429
  function processFile(f, content, mime) {
373
- const podlite_document = parseFile(f, content, mime);
430
+ const text = content || fs.readFileSync(f).toString();
431
+ const podlite_document = parseText(f, text, mime);
374
432
  // now extract some extra meta inforamtion, like pubdate, puburl
375
433
  // markdown front matter and pod attributes reach here as different shapes
376
434
  const attr = ((f, node) => {
377
- if (getParserTypeforFile(f, mime) === PARSER_TYPES.MARKDOWN) {
435
+ if (getParserTypeforFile(f, mime) === exports.PARSER_TYPES.MARKDOWN) {
378
436
  // try to extract from markdown front matter
379
- const { data } = (0, gray_matter_1.default)(content || fs.readFileSync(f).toString());
437
+ const { data } = (0, gray_matter_1.default)(text);
380
438
  return data;
381
439
  }
382
440
  else {
@@ -385,7 +443,7 @@ function processFile(f, content, mime) {
385
443
  })(f, podlite_document);
386
444
  // prepare attributes
387
445
  const { title, description, subtitle, author, footer, puburl, pubdate, header } = attr;
388
- return {
446
+ const record = {
389
447
  type: 'page',
390
448
  isPage: attr.isPage === true || attr.type === 'page',
391
449
  title,
@@ -400,6 +458,7 @@ function processFile(f, content, mime) {
400
458
  sources: [],
401
459
  node: podlite_document,
402
460
  };
461
+ return (0, source_1.withSource)(record, f, text, mime);
403
462
  }
404
463
  function parseSources(path) {
405
464
  let count = 0;
@@ -6,6 +6,7 @@ exports.getPages = getPages;
6
6
  const schema_1 = require("@podlite/schema");
7
7
  const node_utils_1 = require("./node-utils");
8
8
  const shared_1 = require("./shared");
9
+ const source_1 = require("./source");
9
10
  function getArticles(item) {
10
11
  let articles = [];
11
12
  const { file } = item;
@@ -30,7 +31,7 @@ function getArticles(item) {
30
31
  const description = (0, schema_1.getFromTree)(articleContent, 'para')[0];
31
32
  const pubdate = (0, schema_1.makeAttrs)(nodePublished, {}).getFirstValue('pubdate');
32
33
  //TODO: use footer and header of document for generated articles
33
- articles.push({
34
+ articles.push((0, source_1.withOrigin)({
34
35
  pubdate,
35
36
  title: (0, schema_1.getTextContentFromNode)(nodePublished).trim(),
36
37
  type: 'page',
@@ -40,7 +41,7 @@ function getArticles(item) {
40
41
  node: (0, schema_1.mkRootBlock)({}, articleContent),
41
42
  description,
42
43
  file,
43
- });
44
+ }, item));
44
45
  }
45
46
  }
46
47
  }
@@ -68,7 +69,7 @@ function getNotes(item) {
68
69
  ? a_pubdate.replace(' ', 'T')
69
70
  : a_pubdate;
70
71
  //TODO: use footer and header of document for generated notes
71
- return {
72
+ return (0, source_1.withOrigin)({
72
73
  pubdate,
73
74
  type: 'note',
74
75
  isPage: false,
@@ -78,7 +79,7 @@ function getNotes(item) {
78
79
  file,
79
80
  publishUrl: '',
80
81
  sources: [],
81
- };
82
+ }, item);
82
83
  });
83
84
  return notes;
84
85
  }
@@ -89,7 +90,7 @@ function getPages(item) {
89
90
  .map((n) => {
90
91
  const { title, description, puburl, pubdate, isPage } = (0, node_utils_1.getPublishAttributes)(n);
91
92
  //TODO: use footer and header of document for generated pages
92
- return {
93
+ const page = {
93
94
  pubdate: pubdate || '',
94
95
  type: 'page',
95
96
  isPage,
@@ -100,6 +101,7 @@ function getPages(item) {
100
101
  publishUrl: puburl || '',
101
102
  sources,
102
103
  };
104
+ return (0, source_1.withOrigin)(page, item);
103
105
  });
104
106
  return pages;
105
107
  }
@@ -38,6 +38,7 @@ const constants_1 = require("./constants");
38
38
  const fs = __importStar(require("fs"));
39
39
  const node_utils_1 = require("./node-utils");
40
40
  const shared_1 = require("./shared");
41
+ const source_1 = require("./source");
41
42
  const plugin = () => {
42
43
  const componensMap = new Map();
43
44
  const processedNodes = new WeakSet();
@@ -74,7 +75,9 @@ export default {}
74
75
  const { component, source } = (importMatchResult || {
75
76
  groups: { component: undefined, source: undefined },
76
77
  }).groups;
77
- const { path } = source.match(/^\.{0,2}\//) ? (0, node_utils_1.getPathToOpen)(source, file) : { path: source };
78
+ // an import an include brought is found from the file it was written in
79
+ const from = (0, source_1.nodeOrigin)(node)?.file ?? file;
80
+ const { path } = source.match(/^\.{0,2}\//) ? (0, node_utils_1.getPathToOpen)(source, from) : { path: source };
78
81
  // save absolute Component path and Component name
79
82
  const notDefaultImport = component.match(/{(.*)}/);
80
83
  if (notDefaultImport) {
@@ -103,6 +106,11 @@ export default {}
103
106
  return;
104
107
  },
105
108
  React: (node, ctx, interator) => {
109
+ // the reader of the record has read the body in its place; a body it left
110
+ // as text, its lines not found in the file, is read here as before
111
+ const raw = Array.isArray(node.content) && node.content.every(part => part && part.type === 'verbatim');
112
+ if (!raw)
113
+ return { ...node, content: interator(node.content, ctx) };
106
114
  const text = (0, schema_1.getTextContentFromNode)(node);
107
115
  const doc = (0, shared_1.makeAstFromSrc)(text);
108
116
  return { ...node, content: [interator(doc.content, ctx)] };
@@ -0,0 +1,5 @@
1
+ import type { ScopedBlock } from '@podlite/schema';
2
+ export declare const isReadBody: (block: ScopedBlock) => boolean;
3
+ export declare const readRecordText: (text: string, file: string, config?: import("@podlite/schema").ConfigScope, extras?: Pick<import("@podlite/schema").parseOpt, "recognition" | "diagnostics"> & {
4
+ format?: import("podlite").ReadFormat;
5
+ }) => import("@podlite/schema").RootBlock | import("@podlite/schema").AstTree;
package/lib/reading.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readRecordText = exports.isReadBody = void 0;
4
+ const podlite_1 = require("podlite");
5
+ /*
6
+ =begin pod :kind<module>
7
+
8
+ =head2 reading
9
+
10
+ How the publisher reads a record, and the text an include brings into it.
11
+
12
+ =end pod
13
+ */
14
+ /*
15
+ =begin pod :kind<export>
16
+
17
+ =head2 isReadBody
18
+
19
+ Whether the raw body of a block is Podlite text to be read in its place: the
20
+ body of C<=React> is.
21
+
22
+ =end pod
23
+ */
24
+ const isReadBody = (block) => block.name === 'React';
25
+ exports.isReadBody = isReadBody;
26
+ /*
27
+ =begin pod :kind<export>
28
+
29
+ =head2 readRecordText
30
+
31
+ Reads a text as a record of that file name is read, with the body of C<=React>
32
+ read in its place. An include is given the same reader, so the body of
33
+ C<=React> in an included file is read as well.
34
+
35
+ =end pod
36
+ */
37
+ exports.readRecordText = (0, podlite_1.readerFor)((0, podlite_1.podlite)({ importPlugins: true }), { body: exports.isReadBody });
38
+ //# sourceMappingURL=reading.js.map
package/lib/record.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { PodliteDocument, PodNode } from '@podlite/schema';
2
+ export { recordSource, recordOrigin, isParsedTree, nodeOrigin } from './source';
3
+ export type { RecordSource, NodeOrigin } from './source';
2
4
  export type pubRecord = {
3
5
  type: string;
4
6
  pubdate: string;
package/lib/record.js CHANGED
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEntry = void 0;
3
+ exports.isEntry = exports.nodeOrigin = exports.isParsedTree = exports.recordOrigin = exports.recordSource = void 0;
4
+ var source_1 = require("./source");
5
+ Object.defineProperty(exports, "recordSource", { enumerable: true, get: function () { return source_1.recordSource; } });
6
+ Object.defineProperty(exports, "recordOrigin", { enumerable: true, get: function () { return source_1.recordOrigin; } });
7
+ Object.defineProperty(exports, "isParsedTree", { enumerable: true, get: function () { return source_1.isParsedTree; } });
8
+ Object.defineProperty(exports, "nodeOrigin", { enumerable: true, get: function () { return source_1.nodeOrigin; } });
4
9
  // The record's `type` cannot answer this: it says whether the address was declared
5
10
  // or built, and it is the letter the short url is made of. Only the author can call
6
11
  // a document a page, with :type('page'); a document with no date is not published.
@@ -1,6 +1,7 @@
1
1
  import { publishRecord } from './record';
2
2
  import { PodliteWebPlugin } from './plugins';
3
3
  export declare function buildStylesContent(theme: string | undefined, globalStylesPath: string | undefined): string;
4
+ export declare const SITE_DATA_DOCUMENT = "PLUGIN_DATA";
4
5
  export interface SiteInfo {
5
6
  redirects: {
6
7
  source: string;
@@ -36,6 +36,7 @@ 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.SITE_DATA_DOCUMENT = void 0;
39
40
  exports.buildStylesContent = buildStylesContent;
40
41
  const schema_1 = require("@podlite/schema");
41
42
  const constants_1 = require("./constants");
@@ -53,6 +54,17 @@ function buildStylesContent(theme, globalStylesPath) {
53
54
  imports.push(`@import '@Styles/default';`);
54
55
  return imports.map(i => `\n ${i}\n `).join('');
55
56
  }
57
+ /*
58
+ =begin pod :kind<export>
59
+
60
+ =head2 SITE_DATA_DOCUMENT
61
+
62
+ The name an include finds the document this plugin makes by. The document is
63
+ made after the other plugins ran, so the include plugin waits for it.
64
+
65
+ =end pod
66
+ */
67
+ exports.SITE_DATA_DOCUMENT = 'PLUGIN_DATA';
56
68
  const plugin = ({ public_path = constants_1.PUBLIC_PATH, indexFilePath = `${constants_1.POSTS_PATH}/${constants_1.INDEX_PATH}`, built_path = constants_1.BUILT_PATH, site_url, }) => {
57
69
  let indexPage;
58
70
  let redirects = [];
@@ -156,7 +168,7 @@ const plugin = ({ public_path = constants_1.PUBLIC_PATH, indexFilePath = `${cons
156
168
  const articlesJSON = JSON.stringify(recs.filter(i => i.publishUrl).filter(record_1.isEntry));
157
169
  const storeFile = `
158
170
  =begin pod
159
- =for NAME :id<PLUGIN_DATA>
171
+ =for NAME :id<${exports.SITE_DATA_DOCUMENT}>
160
172
  SITE DATA
161
173
  =begin data :id<articles>
162
174
  ${articlesJSON}
@@ -0,0 +1,19 @@
1
+ import type { MimeTypes } from './node-utils';
2
+ export type RecordSource = {
3
+ readonly file: string;
4
+ readonly mime?: MimeTypes;
5
+ readonly text: string;
6
+ };
7
+ export declare const sourceKey: unique symbol;
8
+ export declare const originKey: unique symbol;
9
+ export declare const withSource: <T extends object>(record: T, file: string, text: string, mime?: MimeTypes) => T;
10
+ export declare const withOrigin: <T extends object>(record: T, from: object) => T;
11
+ export declare const recordSource: (record: object) => RecordSource | undefined;
12
+ export declare const recordOrigin: (record: object) => RecordSource | undefined;
13
+ export declare const isParsedTree: (record: object) => boolean;
14
+ export declare const nodeOriginKey: unique symbol;
15
+ export type NodeOrigin = {
16
+ readonly file: string;
17
+ readonly via?: string;
18
+ };
19
+ export declare const nodeOrigin: (node: object) => NodeOrigin | undefined;
package/lib/source.js ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeOrigin = exports.nodeOriginKey = exports.isParsedTree = exports.recordOrigin = exports.recordSource = exports.withOrigin = exports.withSource = exports.originKey = exports.sourceKey = void 0;
4
+ // Symbol.for shares the key between copies of the package in one process, so the
5
+ // shape of the value is fixed by the number in the name
6
+ exports.sourceKey = Symbol.for('@podlite/publisher:source/1');
7
+ exports.originKey = Symbol.for('@podlite/publisher:origin/1');
8
+ // the keys stay out of the record type: a declaration that spreads a record would have to name them
9
+ const held = (record) => record;
10
+ const hold = (file, text, mime, tree) => {
11
+ const source = { file, ...(mime ? { mime } : {}), text, parsed: (node) => node === tree };
12
+ Object.defineProperty(source, 'text', { enumerable: false });
13
+ Object.defineProperty(source, 'parsed', { enumerable: false });
14
+ return Object.freeze(source);
15
+ };
16
+ const withSource = (record, file, text, mime) => ({
17
+ ...record,
18
+ [exports.sourceKey]: hold(file, text, mime, held(record).node),
19
+ });
20
+ exports.withSource = withSource;
21
+ const withOrigin = (record, from) => {
22
+ const origin = held(from)[exports.originKey] ?? held(from)[exports.sourceKey];
23
+ return origin ? { ...record, [exports.originKey]: origin } : record;
24
+ };
25
+ exports.withOrigin = withOrigin;
26
+ /*
27
+ =begin pod :kind<export>
28
+
29
+ =head2 recordSource
30
+
31
+ The source of a record that was read from a text, and of every copy of it. A
32
+ record a plugin built out of parts of another one has no source of its own; see
33
+ C<recordOrigin>. A plugin that replaces the tree of a record leaves the source
34
+ in place, so having a source does not mean the tree still matches it; see
35
+ C<isParsedTree>.
36
+
37
+ =end pod
38
+ */
39
+ const recordSource = (record) => held(record)[exports.sourceKey];
40
+ exports.recordSource = recordSource;
41
+ /*
42
+ =begin pod :kind<export>
43
+
44
+ =head2 recordOrigin
45
+
46
+ The reading a record comes from: its own source, or the source of the record it
47
+ was cut from. Several records cut from one file share one origin, and that
48
+ origin holds the text of the whole file, not of the record.
49
+
50
+ =end pod
51
+ */
52
+ const recordOrigin = (record) => held(record)[exports.originKey] ?? held(record)[exports.sourceKey];
53
+ exports.recordOrigin = recordOrigin;
54
+ /*
55
+ =begin pod :kind<export>
56
+
57
+ =head2 isParsedTree
58
+
59
+ Whether the tree of the record is the very object its source was parsed into.
60
+ A tree changed in place still answers yes.
61
+
62
+ =end pod
63
+ */
64
+ const isParsedTree = (record) => held(record)[exports.sourceKey]?.parsed(held(record).node) ?? false;
65
+ exports.isParsedTree = isParsedTree;
66
+ /*
67
+ =begin pod :kind<export>
68
+
69
+ =head2 nodeOriginKey
70
+
71
+ The key a node holds its C<NodeOrigin> under. Every copy made by spreading the
72
+ node keeps it, and JSON does not carry it. Read it with C<nodeOrigin>.
73
+
74
+ =end pod
75
+ */
76
+ exports.nodeOriginKey = Symbol.for('@podlite/publisher:node-origin/1');
77
+ /*
78
+ =begin pod :kind<export>
79
+
80
+ =head2 nodeOrigin
81
+
82
+ The file a node of a record was written in, when the include plugin knows it:
83
+ the paths written in the node are resolved from that file. A node without one
84
+ was written in the file of the record.
85
+
86
+ =end pod
87
+ */
88
+ const isNodeOrigin = (value) => typeof value === 'object' && value !== null && 'file' in value && typeof value.file === 'string';
89
+ const nodeOrigin = (node) => {
90
+ const mark = Reflect.get(node, exports.nodeOriginKey);
91
+ return isNodeOrigin(mark) ? mark : undefined;
92
+ };
93
+ exports.nodeOrigin = nodeOrigin;
94
+ //# sourceMappingURL=source.js.map
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.51";
1
+ export declare const version = "0.0.53";
package/lib/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // generated by scripts/inject-version.mjs — do not edit by hand
5
- exports.version = '0.0.51';
5
+ exports.version = '0.0.53';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podlite/publisher",
3
- "version": "0.0.51",
3
+ "version": "0.0.53",
4
4
  "description": "Publishing toolkit for Podlite — transform documents to HTML, generate sites",
5
5
  "main": "./lib/index.js",
6
6
  "sideEffects": false,
@@ -84,14 +84,14 @@
84
84
  "transform"
85
85
  ],
86
86
  "dependencies": {
87
- "@podlite/markdown": "0.0.63",
88
- "@podlite/schema": "0.0.70",
87
+ "@podlite/markdown": "0.0.65",
88
+ "@podlite/schema": "0.0.72",
89
89
  "crc-32": "^1.2.2",
90
90
  "glob": "^7.2.0",
91
91
  "gray-matter": "^4.0.3",
92
92
  "iso_9": "^1.0.4",
93
93
  "newbase60": "^1.3.1",
94
- "podlite": "0.0.83"
94
+ "podlite": "0.0.85"
95
95
  },
96
96
  "devDependencies": {
97
97
  "@types/node": "^17.0.7",