@podlite/publisher 0.0.52 → 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 (52) hide show
  1. package/CHANGELOG.podlite +26 -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 +235 -104
  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 +3 -2
  14. package/esm/node-utils.js +60 -19
  15. package/esm/node-utils.js.map +1 -1
  16. package/esm/react-plugin.js +9 -1
  17. package/esm/react-plugin.js.map +1 -1
  18. package/esm/reading.d.ts +5 -0
  19. package/esm/reading.js +34 -0
  20. package/esm/reading.js.map +1 -0
  21. package/esm/record.d.ts +2 -2
  22. package/esm/record.js +1 -1
  23. package/esm/record.js.map +1 -1
  24. package/esm/site-data-plugin.d.ts +1 -0
  25. package/esm/site-data-plugin.js +12 -1
  26. package/esm/site-data-plugin.js.map +1 -1
  27. package/esm/source.d.ts +6 -0
  28. package/esm/source.js +27 -0
  29. package/esm/source.js.map +1 -1
  30. package/esm/version.d.ts +1 -1
  31. package/esm/version.js +1 -1
  32. package/lib/catalogue.d.ts +17 -0
  33. package/lib/catalogue.js +197 -0
  34. package/lib/images-plugin.js +3 -1
  35. package/lib/include-resolve-plugin.d.ts +16 -1
  36. package/lib/include-resolve-plugin.js +270 -103
  37. package/lib/links-plugin.d.ts +9 -1
  38. package/lib/links-plugin.js +177 -56
  39. package/lib/node-utils.d.ts +3 -2
  40. package/lib/node-utils.js +73 -31
  41. package/lib/react-plugin.js +9 -1
  42. package/lib/reading.d.ts +5 -0
  43. package/lib/reading.js +38 -0
  44. package/lib/record.d.ts +2 -2
  45. package/lib/record.js +2 -1
  46. package/lib/site-data-plugin.d.ts +1 -0
  47. package/lib/site-data-plugin.js +13 -1
  48. package/lib/source.d.ts +6 -0
  49. package/lib/source.js +29 -1
  50. package/lib/version.d.ts +1 -1
  51. package/lib/version.js +1 -1
  52. package/package.json +4 -4
@@ -1,86 +1,207 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.LinkError = void 0;
37
+ const path = __importStar(require("path"));
3
38
  const schema_1 = require("@podlite/schema");
4
39
  const node_utils_1 = require("./node-utils");
5
- const plugin = () => {
40
+ const source_1 = require("./source");
41
+ /*
42
+ =begin pod :kind<export>
43
+
44
+ =head2 LinkError
45
+
46
+ A C<doc:> link whose name no published document answers to, or that two
47
+ documents answer to, stops the build. C<problems> holds one line for each.
48
+
49
+ =end pod
50
+ */
51
+ class LinkError extends Error {
52
+ problems;
53
+ constructor(problems) {
54
+ super(`a link does not resolve:\n${problems.map(line => ` ${line}`).join('\n')}`);
55
+ this.name = 'LinkError';
56
+ this.problems = problems;
57
+ }
58
+ }
59
+ exports.LinkError = LinkError;
60
+ const isNode = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
61
+ const shown = (file) => (path.isAbsolute(file) ? path.relative(process.cwd(), file) : file);
62
+ // the file a record was read from, or cut out of
63
+ const fileOf = (record) => path.resolve((0, source_1.recordOrigin)(record)?.file ?? record.file);
64
+ const plugin = (options = {}) => {
6
65
  const outCtx = {};
7
- const docsMap = new Map();
8
66
  const onExit = ctx => ({ ...ctx, ...outCtx });
9
- const processNode = (node, srcfile) => {
10
- const rules = {
11
- 'L<>': node => {
12
- const { content, meta } = node;
13
- const link = meta ? meta : (0, schema_1.getTextContentFromNode)(content);
14
- const r = link.match(/doc:\s*(?<path>(.+))\s*$/);
15
- if (r?.groups?.path) {
16
- const docLink = r.groups.path;
17
- const { isRemote } = (0, node_utils_1.getPathToOpen)(docLink, srcfile);
18
- if (isRemote) {
19
- return node;
20
- }
21
- let title;
22
- let url;
23
- if (!docsMap.has(docLink)) {
24
- console.error(`doc: ${docLink} not found`);
25
- title = `doc: ${docLink} not found`;
26
- url = `doc: ${docLink} not found`;
27
- }
28
- else {
29
- const { title: title1, url: url1 } = docsMap.get(docLink);
30
- title = title1;
31
- url = url1;
32
- }
33
- const newContent = {
34
- type: 'text',
35
- value: `${title}`,
36
- };
37
- const updated = meta ? { meta: url } : { content: newContent, meta: url };
38
- return { ...node, ...updated };
39
- }
40
- return node;
41
- },
42
- };
43
- return (0, schema_1.makeInterator)(rules)(node, {});
44
- };
45
67
  const onProcess = (recs) => {
46
- // const collectlinksMap = makeLinksMap(recs)
47
- // collects docsMap map doc: to file
48
- for (const item of recs) {
49
- // get =TITLE
68
+ // the records that answer to each name, with the text of the block that names them
69
+ const named = new Map();
70
+ for (const record of recs) {
50
71
  const handler = node => {
72
+ // a name an include brought belongs to the document it was written in
73
+ const from = (0, source_1.nodeOrigin)(node)?.file;
74
+ if (from !== undefined && path.resolve(from) !== fileOf(record))
75
+ return;
51
76
  const conf = (0, schema_1.makeAttrs)(node, {});
52
77
  const title = (0, schema_1.getTextContentFromNode)(node).trim();
53
- if (conf.exists('id')) {
54
- const id = conf.getFirstValue('id');
55
- if (id) {
56
- docsMap.set(id, { file: item.file, title, url: item.publishUrl });
57
- }
78
+ const id = conf.exists('id') ? conf.getFirstValue('id') : undefined;
79
+ for (const name of new Set([id, title].filter(Boolean))) {
80
+ named.set(name, [...(named.get(name) ?? []), { record, title }]);
58
81
  }
59
- docsMap.set(title, { file: item.file, title, url: item.publishUrl });
60
82
  };
61
- (0, schema_1.makeInterator)({
62
- NAME: handler,
63
- TITLE: handler,
64
- })(item.node, {});
83
+ (0, schema_1.makeInterator)({ NAME: handler, TITLE: handler })(record.node, {});
65
84
  }
85
+ const problems = [];
86
+ // the address a page gives a section, by the rule the page is drawn with: empty
87
+ // for the block that names the document, which is the page itself
88
+ const addressIn = (record, section) => {
89
+ const bindings = (0, schema_1.buildBindingIndex)(record.node);
90
+ const bound = (0, schema_1.bindTarget)(section, bindings);
91
+ if (bound.found && isNode(bound.node) && (bound.node.name === 'NAME' || bound.node.name === 'TITLE'))
92
+ return '';
93
+ return (0, schema_1.sameDocTarget)(`#${section}`, { __bindings: bindings, __anchors: (0, schema_1.indexAnchors)(record.node) });
94
+ };
95
+ const home = options.home === undefined ? undefined : path.resolve(options.home);
96
+ const addressOf = (record) => record.publishUrl || (home !== undefined && path.resolve(record.file) === home ? '/' : '');
97
+ // the title and the address a name links to: of one document, at the place a
98
+ // search engine is told to index when it is published at more than one
99
+ const resolve = (name, section, at) => {
100
+ // a link has no place of its own; `at` is where the paragraph holding it starts
101
+ const written = section === undefined ? name : `${name}#${section}`;
102
+ const answering = (named.get(name) ?? []).filter(({ record }) => Boolean(addressOf(record)));
103
+ const files = options.documents
104
+ ? options.documents(name).map(file => path.resolve(file))
105
+ : [...new Set(answering.map(({ record }) => fileOf(record)))];
106
+ if (files.length > 1) {
107
+ problems.push(`${at}: a link in the text from this line, doc:${written}: more than one document is named ${name}: ${files
108
+ .map(shown)
109
+ .join(', ')}`);
110
+ return undefined;
111
+ }
112
+ const placed = answering.filter(({ record }) => fileOf(record) === files[0]);
113
+ if (!placed.length) {
114
+ problems.push(`${at}: a link in the text from this line, doc:${written}: no published document is named ${name}`);
115
+ return undefined;
116
+ }
117
+ const indexed = placed.filter(({ record }) => (0, node_utils_1.isIndexed)(record));
118
+ const { record, title } = (indexed.length ? indexed : placed)[(indexed.length ? indexed : placed).length - 1];
119
+ const url = addressOf(record);
120
+ if (section === undefined)
121
+ return { title, url };
122
+ // a section is the block the page gives that address to, by the rule the page is drawn with
123
+ const anchor = addressIn(record, section);
124
+ if (anchor === undefined) {
125
+ problems.push(`${at}: a link in the text from this line, doc:${written}: ${name} has no section ${section}`);
126
+ return undefined;
127
+ }
128
+ return { title, url: `${url}${anchor}` };
129
+ };
130
+ const processNode = (node, srcfile, page) => {
131
+ // the line the paragraph or block holding each link starts at
132
+ const lines = new WeakMap();
133
+ const mark = (tree, line) => {
134
+ if (Array.isArray(tree))
135
+ return tree.forEach(child => mark(child, line));
136
+ if (!isNode(tree))
137
+ return;
138
+ const here = (tree.type === 'block' || tree.type === 'para') && tree.location ? tree.location.start.line : line;
139
+ if (tree.type === 'fcode' && tree.name === 'L' && here !== undefined)
140
+ lines.set(tree, here);
141
+ mark(tree.content, here);
142
+ };
143
+ mark(node);
144
+ const rules = {
145
+ 'L<>': node => {
146
+ const { content, meta } = node;
147
+ const link = meta ? meta : (0, schema_1.getTextContentFromNode)(content);
148
+ const r = link.match(/doc:\s*(?<path>(.+))\s*$/);
149
+ if (r?.groups?.path) {
150
+ const docLink = r.groups.path;
151
+ const from = (0, source_1.nodeOrigin)(node)?.file ?? srcfile;
152
+ const { isRemote } = (0, node_utils_1.getPathToOpen)(docLink, from);
153
+ if (isRemote) {
154
+ return node;
155
+ }
156
+ const line = lines.get(node);
157
+ const at = `${shown(from)}${line !== undefined ? `:${line}` : ''}`;
158
+ // a section of the document is addressed after its name, of this page without one
159
+ const [name, ...section] = docLink.split('#');
160
+ const local = (written) => {
161
+ const anchor = addressIn(page, written);
162
+ if (anchor !== undefined)
163
+ return { title: written, url: anchor || '#' };
164
+ problems.push(`${at}: a link in the text from this line, doc:#${written}: the page has no section ${written}`);
165
+ return undefined;
166
+ };
167
+ const found = name === '' && section.length
168
+ ? local(section.join('#'))
169
+ : resolve(name, section.length ? section.join('#') : undefined, at);
170
+ if (!found)
171
+ return node;
172
+ const { url } = found;
173
+ const newContent = {
174
+ type: 'text',
175
+ value: `${found.title}`,
176
+ };
177
+ const updated = meta ? { meta: url } : { content: newContent, meta: url };
178
+ return { ...node, ...updated };
179
+ }
180
+ return node;
181
+ },
182
+ };
183
+ return (0, schema_1.makeInterator)(rules)(node, {});
184
+ };
66
185
  // convert all doc: links to file:: links
67
186
  const docToFileLinksConverted = recs.map(item => {
68
- const node = processNode(item.node, item.file);
187
+ const node = processNode(item.node, item.file, item);
69
188
  // process images inside description
70
189
  let extra = {};
71
190
  if (item.description) {
72
- extra.description = processNode(item.description, item.file);
191
+ extra.description = processNode(item.description, item.file, item);
73
192
  }
74
193
  // process file header and footer
75
194
  const { footer, header } = item;
76
195
  if (footer) {
77
- extra.footer = processNode(footer, item.file);
196
+ extra.footer = processNode(footer, item.file, item);
78
197
  }
79
198
  if (header) {
80
- extra.header = processNode(header, item.file);
199
+ extra.header = processNode(header, item.file, item);
81
200
  }
82
201
  return { ...item, node, ...extra };
83
202
  });
203
+ if (problems.length)
204
+ throw new LinkError([...new Set(problems)]);
84
205
  return (0, node_utils_1.convertFileLinksToUrl)(docToFileLinksConverted);
85
206
  };
86
207
  return [onProcess, onExit];
@@ -4,12 +4,13 @@ export declare const getPathToOpen: (filepath: any, parentDocPath: any) => {
4
4
  isRemote: boolean;
5
5
  path: any;
6
6
  };
7
+ export declare const isIndexed: (record: publishRecord) => boolean;
7
8
  export declare const makeLinksMap: (records: publishRecord[]) => {
8
- [link: string]: string;
9
+ [link: string]: string | null;
9
10
  };
10
11
  export declare const convertFileLinksToUrl: (records: publishRecord[], additinalMap?: {}) => publishRecord[];
11
12
  export declare function parseFiles(path: string): pubRecord[];
12
- declare const PARSER_TYPES: {
13
+ export declare const PARSER_TYPES: {
13
14
  MARKDOWN: "markdown";
14
15
  PODLITE: "podlite";
15
16
  DEFAULT: "default";
package/lib/node-utils.js CHANGED
@@ -36,7 +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.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
42
  exports.parseText = parseText;
@@ -53,9 +53,9 @@ const path_1 = __importDefault(require("path"));
53
53
  const glob_1 = __importDefault(require("glob"));
54
54
  const shared_1 = require("./shared");
55
55
  const markdown_1 = require("@podlite/markdown");
56
- const podlite_1 = require("podlite");
57
56
  const gray_matter_1 = __importDefault(require("gray-matter"));
58
57
  const source_1 = require("./source");
58
+ const reading_1 = require("./reading");
59
59
  const getPathToOpen = (filepath, parentDocPath) => {
60
60
  const isRemoteReg = new RegExp(/^(https?|ftp):/);
61
61
  const isRemote = isRemoteReg.test(filepath);
@@ -69,10 +69,46 @@ const getPathToOpen = (filepath, parentDocPath) => {
69
69
  };
70
70
  };
71
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
+ */
72
99
  const makeLinksMap = (records) => {
73
- const linksMap = {
74
- ...Object.fromEntries(records.map(({ publishUrl = '', file }) => [(0, exports.getPathToOpen)(file, './').path, publishUrl])),
75
- };
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
+ }
76
112
  return linksMap;
77
113
  };
78
114
  exports.makeLinksMap = makeLinksMap;
@@ -85,8 +121,9 @@ const convertFileLinksToUrl = (records, additinalMap = {}) => {
85
121
  const link = meta ? meta : (0, schema_1.getTextContentFromNode)(content);
86
122
  const r = link.match(/file:\s*(?<path>(.+))\s*$/);
87
123
  const convertFileToUrl = filePath => {
88
- const { isRemote, path } = (0, exports.getPathToOpen)(filePath, item.file);
89
- 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)];
90
127
  };
91
128
  const newLink = r?.groups?.path ? convertFileToUrl(r.groups.path) : link;
92
129
  const newContent = {
@@ -176,7 +213,17 @@ function parseFiles(path) {
176
213
  .filter(Boolean);
177
214
  return allFiles;
178
215
  }
179
- 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 = {
180
227
  MARKDOWN: 'markdown',
181
228
  PODLITE: 'podlite',
182
229
  DEFAULT: 'default',
@@ -189,10 +236,10 @@ const MIME_TYPES_EXTENSIONS = {
189
236
  'audio/mpeg': ['.mp3'],
190
237
  };
191
238
  const PARSER_TYPE_MIME_TYPES = {
192
- [PARSER_TYPES.PODLITE]: ['text/podlite'],
193
- [PARSER_TYPES.MARKDOWN]: ['text/markdown'],
194
- [PARSER_TYPES.DEFAULT]: ['text/plain'],
195
- [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'],
196
243
  };
197
244
  function getParserTypeforFile(filePath, mime) {
198
245
  // get parser type using PARSER_TYPE_MIME_TYPES
@@ -204,17 +251,17 @@ function getParserTypeforFile(filePath, mime) {
204
251
  }
205
252
  // if not found return default TODO: possible change to error
206
253
  console.warn(`Mime type ${mime} not found, using default parser`);
207
- return PARSER_TYPES.DEFAULT;
254
+ return exports.PARSER_TYPES.DEFAULT;
208
255
  }
209
256
  const ext = path_1.default.extname(filePath).toLowerCase();
210
257
  const parserTypeMap = {
211
- '.md': PARSER_TYPES.MARKDOWN,
212
- '.markdown': PARSER_TYPES.MARKDOWN,
213
- '.podlite': PARSER_TYPES.PODLITE,
214
- '.rakudoc': PARSER_TYPES.PODLITE,
215
- '.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,
216
263
  };
217
- return parserTypeMap[ext] || PARSER_TYPES.DEFAULT;
264
+ return parserTypeMap[ext] || exports.PARSER_TYPES.DEFAULT;
218
265
  }
219
266
  /*
220
267
  =begin pod :kind<export>
@@ -227,25 +274,20 @@ nothing is read from disk.
227
274
 
228
275
  =end pod
229
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;
230
279
  function parseText(filePath, text, mime) {
231
280
  // check extension of file and parse it deepnds on mime type
232
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
233
283
  const typeToParserMap = {
234
- [PARSER_TYPES.PODLITE]: (src) => {
235
- const podlite_processor = (0, podlite_1.podlite)({ importPlugins: true }).use({});
236
- const tree = podlite_processor.parse(src, { skipChain: 0, podMode: 1 });
237
- return podlite_processor.toAstResult(tree).interator;
238
- },
284
+ [exports.PARSER_TYPES.PODLITE]: (src) => asDocument((0, reading_1.readRecordText)(src, filePath, undefined, { format: 'podlite' })),
239
285
  //@ts-ignore TODO: fix this
240
- [PARSER_TYPES.MARKDOWN]: (src) => {
286
+ [exports.PARSER_TYPES.MARKDOWN]: (src) => {
241
287
  const { content } = (0, gray_matter_1.default)(src);
242
288
  return (0, markdown_1.parseMd)(content);
243
289
  },
244
- [PARSER_TYPES.DEFAULT]: (src) => {
245
- const podlite_processor = (0, podlite_1.podlite)({ importPlugins: true }).use({});
246
- const tree = podlite_processor.parse(src, { skipChain: 0, podMode: 0 });
247
- return podlite_processor.toAstResult(tree).interator;
248
- },
290
+ [exports.PARSER_TYPES.DEFAULT]: (src) => asDocument((0, reading_1.readRecordText)(src, filePath, undefined, { format: 'default' })),
249
291
  };
250
292
  return typeToParserMap[parser_type](text);
251
293
  }
@@ -390,7 +432,7 @@ function processFile(f, content, mime) {
390
432
  // now extract some extra meta inforamtion, like pubdate, puburl
391
433
  // markdown front matter and pod attributes reach here as different shapes
392
434
  const attr = ((f, node) => {
393
- if (getParserTypeforFile(f, mime) === PARSER_TYPES.MARKDOWN) {
435
+ if (getParserTypeforFile(f, mime) === exports.PARSER_TYPES.MARKDOWN) {
394
436
  // try to extract from markdown front matter
395
437
  const { data } = (0, gray_matter_1.default)(text);
396
438
  return data;
@@ -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,6 +1,6 @@
1
1
  import { PodliteDocument, PodNode } from '@podlite/schema';
2
- export { recordSource, recordOrigin, isParsedTree } from './source';
3
- export type { RecordSource } from './source';
2
+ export { recordSource, recordOrigin, isParsedTree, nodeOrigin } from './source';
3
+ export type { RecordSource, NodeOrigin } from './source';
4
4
  export type pubRecord = {
5
5
  type: string;
6
6
  pubdate: string;
package/lib/record.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isEntry = exports.isParsedTree = exports.recordOrigin = exports.recordSource = void 0;
3
+ exports.isEntry = exports.nodeOrigin = exports.isParsedTree = exports.recordOrigin = exports.recordSource = void 0;
4
4
  var source_1 = require("./source");
5
5
  Object.defineProperty(exports, "recordSource", { enumerable: true, get: function () { return source_1.recordSource; } });
6
6
  Object.defineProperty(exports, "recordOrigin", { enumerable: true, get: function () { return source_1.recordOrigin; } });
7
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; } });
8
9
  // The record's `type` cannot answer this: it says whether the address was declared
9
10
  // or built, and it is the letter the short url is made of. Only the author can call
10
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}
package/lib/source.d.ts CHANGED
@@ -11,3 +11,9 @@ export declare const withOrigin: <T extends object>(record: T, from: object) =>
11
11
  export declare const recordSource: (record: object) => RecordSource | undefined;
12
12
  export declare const recordOrigin: (record: object) => RecordSource | undefined;
13
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 CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isParsedTree = exports.recordOrigin = exports.recordSource = exports.withOrigin = exports.withSource = exports.originKey = exports.sourceKey = void 0;
3
+ exports.nodeOrigin = exports.nodeOriginKey = exports.isParsedTree = exports.recordOrigin = exports.recordSource = exports.withOrigin = exports.withSource = exports.originKey = exports.sourceKey = void 0;
4
4
  // Symbol.for shares the key between copies of the package in one process, so the
5
5
  // shape of the value is fixed by the number in the name
6
6
  exports.sourceKey = Symbol.for('@podlite/publisher:source/1');
@@ -63,4 +63,32 @@ A tree changed in place still answers yes.
63
63
  */
64
64
  const isParsedTree = (record) => held(record)[exports.sourceKey]?.parsed(held(record).node) ?? false;
65
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;
66
94
  //# sourceMappingURL=source.js.map
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.52";
1
+ export declare const version = "0.0.53";