@sleetch/server 1.0.4

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.
@@ -0,0 +1,53 @@
1
+ import { partial_sleetch_configuration as sleetch_configuration } from "@sleetch/core/configuration";
2
+ //#region src/utils/pages.d.ts
3
+ declare const get_page: (_path: string, _language?: string) => Promise<{
4
+ language: string;
5
+ path: string;
6
+ seo: {
7
+ title: string;
8
+ description: string;
9
+ };
10
+ } | undefined>;
11
+ declare const get_pages: (_language?: string) => Promise<{
12
+ language: string;
13
+ pages: {
14
+ language: string;
15
+ path: string;
16
+ seo: {
17
+ title: string;
18
+ description: string;
19
+ };
20
+ }[];
21
+ }>;
22
+ //#endregion
23
+ //#region src/types/builder.d.ts
24
+ type transformer<T = unknown> = (data: {
25
+ language: string;
26
+ path: string;
27
+ }) => T;
28
+ //#endregion
29
+ //#region src/utils/tree.d.ts
30
+ declare const get_tree: (_language?: string) => Promise<{
31
+ tree: import("@sleetch/core/compiler").tree_object[];
32
+ language: string;
33
+ }>;
34
+ declare const get_static_paths: <T>(transformer: transformer<T>, _language?: string) => Promise<{
35
+ paths: T[];
36
+ language: string;
37
+ }>;
38
+ //#endregion
39
+ //#region src/utils/sitemap.d.ts
40
+ declare function get_sitemap(path_builder: transformer): Promise<string>;
41
+ //#endregion
42
+ //#region src/utils/llms.d.ts
43
+ declare function get_llms(transformer: transformer<string>): Promise<string>;
44
+ //#endregion
45
+ //#region src/utils/rss.d.ts
46
+ declare function get_rss({ site, title, description, transformer }: {
47
+ site: string;
48
+ title: string;
49
+ description: string;
50
+ transformer: transformer<string>;
51
+ }): Promise<string>;
52
+ //#endregion
53
+ export { get_llms, get_page, get_pages, get_rss, get_sitemap, get_static_paths, get_tree, type sleetch_configuration };
package/dist/index.js ADDED
@@ -0,0 +1,121 @@
1
+ import { resolve_language, to_flat_tree } from "@sleetch/core/compiler";
2
+ //#region src/utils/tree.ts
3
+ const get_tree = async (_language) => {
4
+ const language = resolve_language(_language);
5
+ const { default: manifest } = await import("@sleetch/client/manifest.js");
6
+ const { default: tree } = await manifest[language]["tree"]();
7
+ return {
8
+ tree,
9
+ language
10
+ };
11
+ };
12
+ const get_static_paths = async (transformer, _language) => {
13
+ const { tree, language } = await get_tree(_language);
14
+ return {
15
+ paths: to_flat_tree(tree).map((page) => transformer({
16
+ language,
17
+ path: page.path
18
+ })),
19
+ language
20
+ };
21
+ };
22
+ const get_languages = async () => {
23
+ const { default: manifest } = await import("@sleetch/client/manifest.js");
24
+ return manifest.languages;
25
+ };
26
+ //#endregion
27
+ //#region src/utils/pages.ts
28
+ const get_page = async (_path, _language) => {
29
+ if (_path.length == 0) _path = "/";
30
+ else if (!_path.startsWith("/", 0)) _path = "/" + _path;
31
+ if (_path.length > 1 && _path.slice(-1) == "/") _path = _path.slice(0, -1);
32
+ const language = resolve_language(_language);
33
+ const { default: manifest } = await import("@sleetch/client/manifest.js");
34
+ for (const path of Object.keys(manifest[language]["markdown_modules"])) if (path == _path) {
35
+ const { default: page } = await manifest[language]["markdown_modules"][path]();
36
+ return {
37
+ language,
38
+ path,
39
+ seo: {
40
+ title: page.frontmatter.title,
41
+ description: page.frontmatter.description
42
+ }
43
+ };
44
+ }
45
+ };
46
+ const get_pages = async (_language) => {
47
+ const { language, paths } = await get_static_paths(async ({ path, language }) => await get_page(path, language), _language);
48
+ return {
49
+ language,
50
+ pages: (await Promise.all(paths)).filter((x) => x != void 0)
51
+ };
52
+ };
53
+ //#endregion
54
+ //#region src/utils/sitemap.ts
55
+ async function get_sitemap(path_builder) {
56
+ const languages = await get_languages();
57
+ const urls = [];
58
+ for (const language of languages) {
59
+ const { paths } = await get_static_paths(path_builder, language);
60
+ for (const path of paths) urls.push(`<url>
61
+ <loc>${path}</loc>
62
+ </url>`);
63
+ }
64
+ return `<?xml version="1.0" encoding="UTF-8"?>
65
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
66
+ ${urls.join("\n ")}
67
+ </urlset>`;
68
+ }
69
+ //#endregion
70
+ //#region src/utils/llms.ts
71
+ async function get_llms(transformer) {
72
+ const languages = await get_languages();
73
+ let txt = "";
74
+ for (const language of languages) {
75
+ txt += `\n## Documentation : language=${language}\n\n`;
76
+ const { pages } = await get_pages(language);
77
+ for (const page of pages) txt += `- [${page.seo.title}](${transformer({
78
+ language,
79
+ path: page.path
80
+ })}) : ${page.seo.description}\n`;
81
+ }
82
+ return txt;
83
+ }
84
+ //#endregion
85
+ //#region src/utils/rss.ts
86
+ function escapeXml(value) {
87
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
88
+ }
89
+ async function get_rss({ site, title, description, transformer }) {
90
+ const languages = await get_languages();
91
+ const items = [];
92
+ for (const language of languages) {
93
+ const { pages } = await get_pages(language);
94
+ for (const page of pages) {
95
+ const url = transformer({
96
+ language,
97
+ path: page.path
98
+ });
99
+ items.push(`
100
+ <item>
101
+ <title>${escapeXml(page.seo.title)}</title>
102
+ <link>${url}</link>
103
+ <guid>${url}</guid>
104
+ <description>${escapeXml(page.seo.description)}</description>
105
+ <language>${language}</language>
106
+ </item>`);
107
+ }
108
+ }
109
+ return `<?xml version="1.0" encoding="UTF-8"?>
110
+ <rss version="2.0">
111
+ <channel>
112
+ <title>${escapeXml(title)}</title>
113
+ <link>${site}</link>
114
+ <description>${escapeXml(description)}</description>
115
+ <lastBuildDate>${(/* @__PURE__ */ new Date()).toUTCString()}</lastBuildDate>
116
+ ${items.join("\n")}
117
+ </channel>
118
+ </rss>`;
119
+ }
120
+ //#endregion
121
+ export { get_llms, get_page, get_pages, get_rss, get_sitemap, get_static_paths, get_tree };
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@sleetch/server",
3
+ "version": "1.0.4",
4
+ "type": "module",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "scripts": {
12
+ "build": "tsdown",
13
+ "dev": "tsdown --watch"
14
+ },
15
+ "dependencies": {
16
+ "@sleetch/core": "1.0.4"
17
+ },
18
+ "peerDependencies": {
19
+ "@sleetch/client": "1.0.4"
20
+ },
21
+ "exports": {
22
+ ".": "./dist/index.js",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "types": "./dist/index.d.ts",
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js"
28
+ }