@paroicms/content-loading-plugin 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/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @paroicms/content-loading-plugin
2
+
3
+ Content loading plugin for ParoiCMS.
4
+
5
+ This package is part of [ParoiCMS](https://www.npmjs.com/package/@paroicms/server).
6
+
7
+ ## License
8
+
9
+ Released under the [MIT license](https://gitlab.com/paroi/opensource/paroicms/-/blob/main/LICENSE.md).
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSearch = makeSearch;
4
+ exports.getPartials = getPartials;
5
+ exports.toLeafId = toLeafId;
6
+ const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
7
+ const public_anywhere_lib_1 = require("@paroicms/public-anywhere-lib");
8
+ async function makeSearch(ctx, query, req, res) {
9
+ const { q, language, limit, start, tpl } = query;
10
+ const words = q.split(/\s+/).filter((word) => word.length >= 2);
11
+ if (words.length === 0)
12
+ return { total: 0 };
13
+ await ctx.renderSearchPartials({
14
+ req,
15
+ res,
16
+ language,
17
+ words,
18
+ limit,
19
+ start,
20
+ templateName: tpl,
21
+ });
22
+ }
23
+ async function getPartials(ctx, req, res, params, labeledById) {
24
+ const documentId = params["children-of"];
25
+ const parentId = (0, public_anywhere_lib_1.parseSectionId)(documentId);
26
+ const labeledByTermId = (0, data_formatters_lib_1.isDef)(labeledById) ? toLeafId(labeledById) : undefined;
27
+ const payload = {
28
+ templateName: params.templateName,
29
+ documentId: documentId,
30
+ offset: params.start,
31
+ limit: params.limit,
32
+ };
33
+ await ctx.renderChildPartials({
34
+ req,
35
+ res,
36
+ params: payload,
37
+ parentDocumentId: parentId,
38
+ labeledByTermId,
39
+ });
40
+ }
41
+ function toLeafId(leafOrSectionId) {
42
+ return leafOrSectionId.indexOf(":") !== -1
43
+ ? (0, public_anywhere_lib_1.parseSectionId)(leafOrSectionId).leafId
44
+ : leafOrSectionId;
45
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.plugin = void 0;
4
+ const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
5
+ const public_server_lib_1 = require("@paroicms/public-server-lib");
6
+ const node_path_1 = require("node:path");
7
+ const controller_1 = require("./controller");
8
+ const projectDir = (0, node_path_1.dirname)(__dirname);
9
+ const packageDir = (0, node_path_1.dirname)(projectDir);
10
+ const version = (0, data_formatters_lib_1.strVal)(require((0, node_path_1.join)(packageDir, "package.json")).version);
11
+ const assetsBaseUrl = `/assets/plugin/content-loading/${version}`;
12
+ exports.plugin = {
13
+ version,
14
+ async siteInit(api) {
15
+ api.setPublicAssetsDirectory((0, node_path_1.join)(packageDir, "public-front", "dist"));
16
+ api.addHeadTag(`<link rel="stylesheet" href="${(0, public_server_lib_1.escapeHtml)(`${assetsBaseUrl}/style.css`)}">`, `<script type="module" src="${(0, public_server_lib_1.escapeHtml)(`${assetsBaseUrl}/public-front-plugin.mjs`)}"></script>`);
17
+ api.setPublicApiHandler(async (ctx, req, res, relativePath) => {
18
+ if (relativePath === "/search") {
19
+ await (0, controller_1.makeSearch)(ctx, req.query, req, res);
20
+ return;
21
+ }
22
+ if (relativePath === "/partials") {
23
+ const labeledById = req.query.labeledById;
24
+ await (0, controller_1.getPartials)(ctx, req, res, req.query, labeledById);
25
+ return;
26
+ }
27
+ res.append("Content-Type", "application/json; charset=utf-8");
28
+ res.status(404).send({ status: 404 });
29
+ return;
30
+ });
31
+ },
32
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@paroicms/content-loading-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Content loading plugin for ParoiCMS",
5
+ "keywords": [
6
+ "paroicms",
7
+ "plugin",
8
+ "content",
9
+ "loading"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://gitlab.com/paroi/opensource/paroicms.git",
14
+ "directory": "plugins/content-loading-plugin"
15
+ },
16
+ "author": "Paroi Team",
17
+ "license": "MIT",
18
+ "scripts": {
19
+ "dev:public": "(cd public-front && vite)",
20
+ "build": "npm run build:backend && npm run build:public",
21
+ "build:backend": "(cd backend && tsc)",
22
+ "build:public": "(cd public-front && tsc && vite build)",
23
+ "clear": "rimraf backend/dist/* public-front/dist/*"
24
+ },
25
+ "dependencies": {
26
+ "@paroi/data-formatters-lib": "~0.4.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@paroicms/public-anywhere-lib": "0",
30
+ "@paroicms/public-server-lib": "0"
31
+ },
32
+ "devDependencies": {
33
+ "@paroicms/public-anywhere-lib": "0.5.0",
34
+ "@paroicms/public-server-lib": "0.12.0",
35
+ "@solid-primitives/i18n": "~2.1.1",
36
+ "@types/node": "~20.12.8",
37
+ "rimraf": "~6.0.1",
38
+ "sass": "~1.77.8",
39
+ "solid-devtools": "~0.30.1",
40
+ "solid-js": "~1.8.17",
41
+ "typescript": "~5.5.4",
42
+ "vite": "~5.2.11",
43
+ "vite-plugin-solid": "~2.10.2"
44
+ },
45
+ "main": "backend/dist/plugin.js",
46
+ "files": [
47
+ "backend/dist",
48
+ "public-front/dist"
49
+ ]
50
+ }