@sleetch/server 1.0.7 → 1.0.9

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 (3) hide show
  1. package/dist/index.d.ts +16 -15
  2. package/dist/index.js +37 -28
  3. package/package.json +27 -26
package/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { partial_sleetch_configuration as sleetch_configuration, path_transformer } from "@sleetch/core/configuration";
2
+ //#region src/utils/llms.d.ts
3
+ declare function get_llms(transformer: path_transformer<string>): Promise<string>;
4
+ //#endregion
2
5
  //#region src/utils/pages.d.ts
3
6
  declare const get_page: (_path: string, _language?: string) => Promise<{
4
7
  language: string;
@@ -20,6 +23,17 @@ declare const get_pages: (_language?: string) => Promise<{
20
23
  }[];
21
24
  }>;
22
25
  //#endregion
26
+ //#region src/utils/rss.d.ts
27
+ declare function get_rss({ site, title, description, transformer }: {
28
+ site: string;
29
+ title: string;
30
+ description: string;
31
+ transformer: path_transformer<string>;
32
+ }): Promise<string>;
33
+ //#endregion
34
+ //#region src/utils/sitemap.d.ts
35
+ declare function get_sitemap(path_builder: path_transformer): Promise<string>;
36
+ //#endregion
23
37
  //#region src/utils/tree.d.ts
24
38
  declare const get_tree: (_language?: string) => Promise<{
25
39
  tree: import("@sleetch/core/compiler").tree_object[];
@@ -29,19 +43,6 @@ declare const get_static_paths: <T>(transformer: path_transformer<T>, _language?
29
43
  paths: T[];
30
44
  language: string;
31
45
  }>;
46
+ declare const get_languages: () => Promise<string[]>;
32
47
  //#endregion
33
- //#region src/utils/sitemap.d.ts
34
- declare function get_sitemap(path_builder: path_transformer): Promise<string>;
35
- //#endregion
36
- //#region src/utils/llms.d.ts
37
- declare function get_llms(transformer: path_transformer<string>): Promise<string>;
38
- //#endregion
39
- //#region src/utils/rss.d.ts
40
- declare function get_rss({ site, title, description, transformer }: {
41
- site: string;
42
- title: string;
43
- description: string;
44
- transformer: path_transformer<string>;
45
- }): Promise<string>;
46
- //#endregion
47
- export { get_llms, get_page, get_pages, get_rss, get_sitemap, get_static_paths, get_tree, type sleetch_configuration };
48
+ export { get_languages, get_llms, get_page, get_pages, get_rss, get_sitemap, get_static_paths, get_tree, type sleetch_configuration };
package/dist/index.js CHANGED
@@ -1,9 +1,21 @@
1
+ import { clean_path } from "@sleetch/client";
1
2
  import { resolve_language, to_flat_tree } from "@sleetch/core/compiler";
3
+ //#region src/utils/manifest.ts
4
+ const isBareESM = typeof module === "undefined" && typeof import.meta !== "undefined" && typeof process !== "undefined" && (!import.meta.env || !import.meta.env.DEV && !import.meta.env.PROD);
5
+ const dynamic_import = new Function("specifier", "return import(specifier)");
6
+ const get_manifest = async () => {
7
+ if (isBareESM) {
8
+ const { default: manifest } = await dynamic_import(`@sleetch/client/manifest-cache-bust?t=${Date.now()}`);
9
+ return manifest;
10
+ }
11
+ const { default: manifest } = await import("@sleetch/client/manifest");
12
+ return manifest;
13
+ };
14
+ //#endregion
2
15
  //#region src/utils/tree.ts
3
16
  const get_tree = async (_language) => {
4
17
  const language = resolve_language(_language);
5
- const { default: manifest } = await import("@sleetch/client/manifest.js");
6
- const { default: tree } = await manifest[language]["tree"]();
18
+ const { default: tree } = await (await get_manifest())[language].tree();
7
19
  return {
8
20
  tree,
9
21
  language
@@ -20,19 +32,16 @@ const get_static_paths = async (transformer, _language) => {
20
32
  };
21
33
  };
22
34
  const get_languages = async () => {
23
- const { default: manifest } = await import("@sleetch/client/manifest.js");
24
- return manifest.languages;
35
+ return (await get_manifest()).languages;
25
36
  };
26
37
  //#endregion
27
38
  //#region src/utils/pages.ts
28
39
  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);
40
+ _path = clean_path(_path);
32
41
  const language = resolve_language(_language);
33
- const { default: manifest } = await import("@sleetch/client/manifest.js");
34
- for (const path of Object.keys(manifest[language]["pages"])) if (path == _path) {
35
- const { default: page } = await manifest[language]["pages"][path]();
42
+ const manifest = await get_manifest();
43
+ for (const path of Object.keys(manifest[language].pages)) if (path === _path) {
44
+ const { default: page } = await manifest[language].pages[path]();
36
45
  return {
37
46
  language,
38
47
  path,
@@ -47,26 +56,10 @@ const get_pages = async (_language) => {
47
56
  const { language, paths } = await get_static_paths(async ({ path, language }) => await get_page(path, language), _language);
48
57
  return {
49
58
  language,
50
- pages: (await Promise.all(paths)).filter((x) => x != void 0)
59
+ pages: (await Promise.all(paths)).filter((x) => x !== void 0)
51
60
  };
52
61
  };
53
62
  //#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
63
  //#region src/utils/llms.ts
71
64
  async function get_llms(transformer) {
72
65
  const languages = await get_languages();
@@ -118,4 +111,20 @@ async function get_rss({ site, title, description, transformer }) {
118
111
  </rss>`;
119
112
  }
120
113
  //#endregion
121
- export { get_llms, get_page, get_pages, get_rss, get_sitemap, get_static_paths, get_tree };
114
+ //#region src/utils/sitemap.ts
115
+ async function get_sitemap(path_builder) {
116
+ const languages = await get_languages();
117
+ const urls = [];
118
+ for (const language of languages) {
119
+ const { paths } = await get_static_paths(path_builder, language);
120
+ for (const path of paths) urls.push(`<url>
121
+ <loc>${path}</loc>
122
+ </url>`);
123
+ }
124
+ return `<?xml version="1.0" encoding="UTF-8"?>
125
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
126
+ ${urls.join("\n ")}
127
+ </urlset>`;
128
+ }
129
+ //#endregion
130
+ export { get_languages, get_llms, get_page, get_pages, get_rss, get_sitemap, get_static_paths, get_tree };
package/package.json CHANGED
@@ -1,28 +1,29 @@
1
1
  {
2
- "name": "@sleetch/server",
3
- "version": "1.0.7",
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.7"
17
- },
18
- "peerDependencies": {
19
- "@sleetch/client": "1.0.7"
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"
2
+ "name": "@sleetch/server",
3
+ "version": "1.0.9",
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.9",
17
+ "@sleetch/client": "1.0.9"
18
+ },
19
+ "peerDependencies": {
20
+ "@sleetch/client": "1.0.9"
21
+ },
22
+ "exports": {
23
+ ".": "./dist/index.js",
24
+ "./package.json": "./package.json"
25
+ },
26
+ "types": "./dist/index.d.ts",
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.js"
28
29
  }