@podlite/publisher 0.0.2

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 (74) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +22 -0
  3. package/README.md +41 -0
  4. package/esm/breadcrumb-plugin.d.ts +3 -0
  5. package/esm/breadcrumb-plugin.js +34 -0
  6. package/esm/breadcrumb-plugin.js.map +1 -0
  7. package/esm/constants.d.ts +27 -0
  8. package/esm/constants.js +28 -0
  9. package/esm/constants.js.map +1 -0
  10. package/esm/images-plugin.d.ts +3 -0
  11. package/esm/images-plugin.js +60 -0
  12. package/esm/images-plugin.js.map +1 -0
  13. package/esm/index.d.ts +4 -0
  14. package/esm/index.js +5 -0
  15. package/esm/index.js.map +1 -0
  16. package/esm/links-plugin.d.ts +3 -0
  17. package/esm/links-plugin.js +87 -0
  18. package/esm/links-plugin.js.map +1 -0
  19. package/esm/node-utils.d.ts +50 -0
  20. package/esm/node-utils.js +376 -0
  21. package/esm/node-utils.js.map +1 -0
  22. package/esm/plugins.d.ts +138 -0
  23. package/esm/plugins.js +147 -0
  24. package/esm/plugins.js.map +1 -0
  25. package/esm/pubdate-plugin.d.ts +9 -0
  26. package/esm/pubdate-plugin.js +137 -0
  27. package/esm/pubdate-plugin.js.map +1 -0
  28. package/esm/react-plugin.d.ts +3 -0
  29. package/esm/react-plugin.js +109 -0
  30. package/esm/react-plugin.js.map +1 -0
  31. package/esm/shared.d.ts +36 -0
  32. package/esm/shared.js +157 -0
  33. package/esm/shared.js.map +1 -0
  34. package/esm/site-data-plugin.d.ts +25 -0
  35. package/esm/site-data-plugin.js +135 -0
  36. package/esm/site-data-plugin.js.map +1 -0
  37. package/esm/state-version-plugin.d.ts +3 -0
  38. package/esm/state-version-plugin.js +23 -0
  39. package/esm/state-version-plugin.js.map +1 -0
  40. package/esm/template-plugin.d.ts +3 -0
  41. package/esm/template-plugin.js +10 -0
  42. package/esm/template-plugin.js.map +1 -0
  43. package/esm/terms-index-plugin.d.ts +5 -0
  44. package/esm/terms-index-plugin.js +108 -0
  45. package/esm/terms-index-plugin.js.map +1 -0
  46. package/lib/breadcrumb-plugin.d.ts +3 -0
  47. package/lib/breadcrumb-plugin.js +36 -0
  48. package/lib/constants.d.ts +27 -0
  49. package/lib/constants.js +34 -0
  50. package/lib/images-plugin.d.ts +3 -0
  51. package/lib/images-plugin.js +84 -0
  52. package/lib/index.d.ts +4 -0
  53. package/lib/index.js +17 -0
  54. package/lib/links-plugin.d.ts +3 -0
  55. package/lib/links-plugin.js +89 -0
  56. package/lib/node-utils.d.ts +50 -0
  57. package/lib/node-utils.js +412 -0
  58. package/lib/plugins.d.ts +138 -0
  59. package/lib/plugins.js +153 -0
  60. package/lib/pubdate-plugin.d.ts +9 -0
  61. package/lib/pubdate-plugin.js +143 -0
  62. package/lib/react-plugin.d.ts +3 -0
  63. package/lib/react-plugin.js +130 -0
  64. package/lib/shared.d.ts +36 -0
  65. package/lib/shared.js +169 -0
  66. package/lib/site-data-plugin.d.ts +25 -0
  67. package/lib/site-data-plugin.js +159 -0
  68. package/lib/state-version-plugin.d.ts +3 -0
  69. package/lib/state-version-plugin.js +44 -0
  70. package/lib/template-plugin.d.ts +3 -0
  71. package/lib/template-plugin.js +12 -0
  72. package/lib/terms-index-plugin.d.ts +5 -0
  73. package/lib/terms-index-plugin.js +129 -0
  74. package/package.json +52 -0
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const schema_1 = require("@podlite/schema");
26
+ const constants_1 = require("./constants");
27
+ const fs = __importStar(require("fs"));
28
+ const _1 = require(".");
29
+ const path_1 = __importDefault(require("path"));
30
+ 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, }) => {
31
+ let indexPage;
32
+ let redirects = [];
33
+ let allRecords = [];
34
+ const outCtx = {};
35
+ const onExit = ctx => {
36
+ let title;
37
+ let subtitle;
38
+ let author;
39
+ let footer = '';
40
+ // collect site metadata like TITLE, SUBTITLE and attributes from pod
41
+ const [pod] = (0, schema_1.getFromTree)(indexPage.node, 'pod');
42
+ const attr = (0, schema_1.makeAttrs)(pod, {});
43
+ const pageAttr = Object.fromEntries(Object.keys(attr.asHash()).map(k => [k, attr.getFirstValue(k)]));
44
+ const { postsPerPage, favicon, puburl, url, globalStyles, gtmId } = pageAttr;
45
+ // process favicon file
46
+ const faviconPath = favicon ? path_1.default.join(path_1.default.dirname(indexFilePath), favicon) : 'src/favicon.png';
47
+ const { base, ext } = path_1.default.parse(faviconPath);
48
+ const faviconFileName = `favicon${ext}`;
49
+ if (!ctx.testing) {
50
+ fs.copyFileSync(faviconPath, `${public_path}/${faviconFileName}`);
51
+ }
52
+ //clean up index page and collect needed data
53
+ const pageNode = (0, schema_1.makeInterator)({
54
+ TITLE: (node, ctx, interator) => {
55
+ title = (0, schema_1.getTextContentFromNode)(node);
56
+ },
57
+ SUBTITLE: (node, ctx, interator) => {
58
+ subtitle = (0, schema_1.getTextContentFromNode)(node);
59
+ },
60
+ AUTHOR: (node, ctx, interator) => {
61
+ const attr = (0, schema_1.makeAttrs)(node, ctx);
62
+ author = Object.fromEntries(Object.keys(attr.asHash()).map(k => [k, attr.getFirstValue(k)]));
63
+ },
64
+ FOOTER: (node, ctx, interator) => {
65
+ footer = node.content;
66
+ },
67
+ })(indexPage.node, {});
68
+ const siteData = {
69
+ postsPerPage,
70
+ favicon: faviconFileName,
71
+ url: site_url || process.env.SITE_URL || url || puburl,
72
+ node: pageNode,
73
+ title,
74
+ globalStyles,
75
+ redirects,
76
+ footer,
77
+ gtmId,
78
+ item: { ...indexPage, node: pageNode },
79
+ };
80
+ // !!! now get previsuly prepared data from context and prepare control.json
81
+ const { stateVersion, nextPublishTime, imagesMap } = ctx;
82
+ const controlJson = {
83
+ stateVersion,
84
+ nextPublishTime,
85
+ };
86
+ if (!ctx.testing) {
87
+ // save control.json
88
+ fs.writeFileSync(`${public_path}/control.json`, JSON.stringify(controlJson, null, 2));
89
+ }
90
+ const dataJson = {
91
+ all: [],
92
+ control: controlJson,
93
+ imagesMap: imagesMap?.size ? Object.fromEntries(imagesMap) : {},
94
+ siteInfo: siteData,
95
+ };
96
+ if (!ctx.testing) {
97
+ (0, _1.streamWriteArray)(allRecords, `${built_path}/pages.json`)
98
+ .then(() => console.log('All pages written successfully'))
99
+ .catch(err => console.error('Error writing file:', err));
100
+ fs.writeFileSync(`${built_path}/data.json`, JSON.stringify(dataJson));
101
+ fs.writeFileSync(`${built_path}/siteInfo.json`, JSON.stringify(siteData, null, 2));
102
+ fs.writeFileSync(`${built_path}/imagesMap.json`, JSON.stringify(imagesMap, null, 2));
103
+ }
104
+ // prepare data for LastArticles component
105
+ if (!ctx.testing) {
106
+ const source = () => allRecords.filter(i => i.publishUrl).filter(({ type = '' }) => type !== 'page');
107
+ const articles = source().reverse().slice(0, 10);
108
+ // if (!articles[articles.length - 1]) {
109
+ // throw new Error('No articles found' + JSON.stringify({'articles.length - 1':articles.length - 1, articles, 'allRecords':allRecords.length}, null, 2))
110
+ // }
111
+ // const lastArticleUrl = articles[articles.length - 1].publishUrl
112
+ // const articleIndex = source().findIndex(({ publishUrl }) => publishUrl === lastArticleUrl)
113
+ // const prev = source()[articleIndex - 1]
114
+ fs.writeFileSync(`${built_path}/lastArticles.json`, JSON.stringify({ articles, prev: {} }, null, 2));
115
+ }
116
+ // process GlobalStyles
117
+ let stylesContent = '';
118
+ if (siteData.globalStyles) {
119
+ const pathFs = require('path');
120
+ const docDirPath = pathFs.dirname(`${built_path}/styles.css`);
121
+ const path = pathFs.relative(docDirPath, pathFs.join(pathFs.dirname(indexFilePath), siteData.globalStyles));
122
+ stylesContent += `
123
+ @import '${path}';
124
+ `;
125
+ }
126
+ else {
127
+ const path = '@Styles/default';
128
+ stylesContent += `
129
+ @import '${path}';
130
+ `;
131
+ }
132
+ if (!ctx.testing) {
133
+ // /built/styles.css
134
+ fs.writeFileSync(`${built_path}/styles.css`, stylesContent, 'utf8');
135
+ }
136
+ return { ...ctx, ...outCtx, siteData };
137
+ };
138
+ const onProcess = (recs) => {
139
+ // collect redirects
140
+ recs.map(item => {
141
+ const { publishUrl, sources } = item;
142
+ sources.forEach(src => {
143
+ redirects.push({ source: src, destination: publishUrl, statusCode: 308 }); //permanent redirect
144
+ });
145
+ });
146
+ // get index page or throw error
147
+ indexPage = recs.find(item => item.file === indexFilePath);
148
+ if (!indexPage) {
149
+ console.log(JSON.stringify(recs.map(i => i.file), null, 2));
150
+ throw new Error('Index page not found. Used path: ' + indexFilePath);
151
+ }
152
+ indexPage.publishUrl = '/';
153
+ allRecords.push(...recs);
154
+ return recs;
155
+ };
156
+ return [onProcess, onExit];
157
+ };
158
+ exports.default = plugin;
159
+ //# sourceMappingURL=site-data-plugin.js.map
@@ -0,0 +1,3 @@
1
+ import { PodliteWebPlugin } from '.';
2
+ declare const plugin: () => PodliteWebPlugin;
3
+ export default plugin;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const CRC32 = __importStar(require("crc-32"));
23
+ const schema_1 = require("@podlite/schema");
24
+ const version = require('../package.json').version;
25
+ const plugin = () => {
26
+ const outCtx = {};
27
+ let crc_sum = '';
28
+ const onExit = ctx => {
29
+ outCtx.stateVersion = CRC32.str(crc_sum) + '+v' + version;
30
+ return { ...ctx, ...outCtx };
31
+ };
32
+ const getStateVersion = (allREcords) => {
33
+ return allREcords.reduce((prev, current) => {
34
+ return prev + CRC32.str((0, schema_1.getTextContentFromNode)(current.node));
35
+ }, '');
36
+ };
37
+ const onProcess = (recs) => {
38
+ crc_sum += getStateVersion(recs);
39
+ return recs;
40
+ };
41
+ return [onProcess, onExit];
42
+ };
43
+ exports.default = plugin;
44
+ //# sourceMappingURL=state-version-plugin.js.map
@@ -0,0 +1,3 @@
1
+ import { PodliteWebPlugin } from '.';
2
+ declare const plugin: () => PodliteWebPlugin;
3
+ export default plugin;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const plugin = () => {
4
+ const outCtx = {};
5
+ const onExit = ctx => ({ ...ctx, ...outCtx });
6
+ const onProcess = (recs) => {
7
+ return recs;
8
+ };
9
+ return [onProcess, onExit];
10
+ };
11
+ exports.default = plugin;
12
+ //# sourceMappingURL=template-plugin.js.map
@@ -0,0 +1,5 @@
1
+ import { PodliteWebPlugin } from '../src';
2
+ declare const plugin: ({ built_path }: {
3
+ built_path?: string;
4
+ }) => PodliteWebPlugin;
5
+ export default plugin;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const schema_1 = require("@podlite/schema");
23
+ const constants_1 = require("../src/constants");
24
+ const fs = __importStar(require("fs"));
25
+ const plugin = ({ built_path = constants_1.BUILT_PATH }) => {
26
+ const outCtx = {};
27
+ const onExit = ctx => {
28
+ if (!ctx.testing) {
29
+ // save control.json
30
+ fs.writeFileSync(`${built_path}/indexTerms.json`, JSON.stringify(outCtx.indexTerms, null, 2));
31
+ }
32
+ return { ...ctx, ...outCtx };
33
+ };
34
+ const isNodeContainsX = (node) => {
35
+ let isExistsDocBlocks = false;
36
+ const rules = {
37
+ 'X<>': (node, ctx, interator) => {
38
+ // skip root block
39
+ isExistsDocBlocks = true;
40
+ },
41
+ };
42
+ (0, schema_1.makeInterator)(rules)(node, {});
43
+ return isExistsDocBlocks;
44
+ };
45
+ function findNearest(arr, index, checkFn) {
46
+ const leftPart = arr.slice(0, index).reverse();
47
+ const rightPart = arr.slice(index + 1);
48
+ const findIndex = (part) => {
49
+ const foundIndex = part.findIndex(item => checkFn(item));
50
+ return foundIndex !== -1 ? foundIndex : null;
51
+ };
52
+ const left = findIndex(leftPart);
53
+ const right = findIndex(rightPart);
54
+ const found = [left != null && leftPart[left], right != null && rightPart[right]].filter(Boolean);
55
+ if (found.length && found.length < 2) {
56
+ return found[0];
57
+ }
58
+ return left < right ? leftPart[left] : rightPart[right];
59
+ }
60
+ const processNode = (node) => {
61
+ const res = [];
62
+ const rules = {
63
+ ':block': (node, ctx, interator) => {
64
+ // ctx.parent = node
65
+ if (node.content) {
66
+ // provess root block content
67
+ return interator(node.content, { ...ctx, parent: node });
68
+ }
69
+ },
70
+ ':para': (node, ctx, interator) => {
71
+ if (['root', 'pod'].includes(ctx.parent.name)) {
72
+ const isEmptyContent = node => (0, schema_1.getTextContentFromNode)(node).match(/^\s*$/);
73
+ if (isNodeContainsX(node)) {
74
+ if (isEmptyContent(node)) {
75
+ const indexOfCurrentNode = ctx.parent.content.findIndex(i => i === node);
76
+ if (indexOfCurrentNode) {
77
+ //find nearest addresable block
78
+ const nearestBlock = findNearest(ctx.parent.content, indexOfCurrentNode, node => {
79
+ // check if node is string
80
+ if (typeof node !== 'string' && 'type' in node) {
81
+ return node.type === 'block';
82
+ }
83
+ return false;
84
+ });
85
+ // set parent nearest addresable block
86
+ if (node.content) {
87
+ // provess root block content
88
+ return interator(node.content, { ...ctx, parent: nearestBlock });
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ if (node.content) {
95
+ // provess root block content
96
+ return interator(node.content, { ...ctx, parent: ctx.parent });
97
+ }
98
+ },
99
+ 'X<>': (node, ctx) => {
100
+ res.push({ xnode: node, parent: ctx.parent });
101
+ },
102
+ };
103
+ (0, schema_1.makeInterator)(rules)(node, {});
104
+ return res;
105
+ };
106
+ const onProcess = (recs) => {
107
+ const res = recs.map(item => {
108
+ const terms = processNode(item.node);
109
+ const termWithUrl = terms.map(({ xnode, parent }) => {
110
+ const urlParts = [item.publishUrl];
111
+ if (parent && typeof parent !== 'string' && 'id' in parent) {
112
+ urlParts.push(parent.id);
113
+ }
114
+ return {
115
+ xnode,
116
+ url: urlParts.join('#'),
117
+ title: item.title,
118
+ subtitle: item.subtitle,
119
+ };
120
+ });
121
+ outCtx.indexTerms = [...(outCtx.indexTerms || []), ...termWithUrl].filter(x => Boolean(x.xnode.entry));
122
+ return { ...item };
123
+ });
124
+ return res;
125
+ };
126
+ return [onProcess, onExit];
127
+ };
128
+ exports.default = plugin;
129
+ //# sourceMappingURL=terms-index-plugin.js.map
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@podlite/publisher",
3
+ "version": "0.0.2",
4
+ "description": "Library that powers publishing and CLI tools for the Podlite markup language",
5
+ "main": "lib/index.js",
6
+ "license": "MIT",
7
+ "files": [
8
+ "lib/**/*.js",
9
+ "lib/**/*.d.ts",
10
+ "esm",
11
+ "README.md",
12
+ "CHANGELOG.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=14"
16
+ },
17
+ "engineStrict": true,
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "main": "lib/index.js",
21
+ "types": "./lib/index.d.ts",
22
+ "module": "./esm/index.js"
23
+ },
24
+ "scripts": {
25
+ "clean": "rm -rf lib esm *.tsbuildinfo",
26
+ "build": "yarn g:build",
27
+ "test": "yarn g:jest --passWithNoTests"
28
+ },
29
+ "keywords": [
30
+ "markdown",
31
+ "podlite",
32
+ "markup",
33
+ "markup-language"
34
+ ],
35
+ "dependencies": {
36
+ "@podlite/schema": "0.0.21",
37
+ "crc-32": "^1.2.2",
38
+ "gray-matter": "^4.0.3",
39
+ "iso_9": "^1.0.4",
40
+ "newbase60": "^1.3.1"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^17.0.7",
44
+ "glob": "^7.2.0",
45
+ "npm-run-all": "^4.1.5",
46
+ "ts-node": "^9.1.1",
47
+ "typescript": "4.5.5"
48
+ },
49
+ "types": "./lib/index.d.ts",
50
+ "modules": "./esm/index.js",
51
+ "module": "./esm/index.js"
52
+ }