@tayacrystals/lore 1.0.0 → 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 tayacrystals
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,30 @@
1
- # lore-2
1
+ # Lore
2
2
 
3
- Simple documentation site generator
3
+ Zero-setup documentation static site generator.
4
4
 
5
- - static site
6
- - js is optional
7
- - fast
5
+ ## Quick Start
6
+
7
+ Run lore in your docs directory:
8
+
9
+ ```bash
10
+ bunx @tayacrystals/lore
11
+ ```
12
+
13
+ This builds your documentation to `./build`. To start a dev server:
14
+
15
+ ```bash
16
+ bunx @tayacrystals/lore dev
17
+ ```
18
+
19
+ ## Documentation
20
+
21
+ For full documentation, visit [https://tayacrystals.github.io/lore/](https://tayacrystals.github.io/lore/)
22
+
23
+ ## Features
24
+
25
+ - Zero setup docs
26
+ - MDX support with custom components
27
+ - Versioning
28
+ - Internationalization
29
+ - Dark/Light mode with system preference detection
30
+ - Full-text search
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tayacrystals/lore",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Simple documentation site generator with versioning and internationalization support",
5
5
  "type": "module",
6
6
  "bin": {
@@ -39,14 +39,12 @@
39
39
  "url": "https://github.com/tayacrystals/lore/issues"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/bun": "latest",
43
- "@types/js-yaml": "^4.0.9"
42
+ "@types/bun": "latest"
44
43
  },
45
44
  "peerDependencies": {
46
45
  "typescript": "^5"
47
46
  },
48
47
  "dependencies": {
49
- "js-yaml": "^4.1.1",
50
48
  "lucide": "^0.577.0",
51
49
  "rehype-autolink-headings": "^7.1.0",
52
50
  "rehype-slug": "^6.0.0",
package/src/build.ts CHANGED
@@ -7,12 +7,12 @@ import { renderPage } from "./template.ts";
7
7
  import { detectVersions, getDefaultVersion } from "./version.ts";
8
8
  import { detectLocales, getDefaultLocale } from "./i18n.ts";
9
9
 
10
- async function findLogo(docsDir: string, outDir: string): Promise<string | undefined> {
10
+ async function findLogo(docsDir: string, outDir: string, baseUrl?: string): Promise<string | undefined> {
11
11
  for (const name of ["logo.svg", "logo.png"]) {
12
12
  const src = Bun.file(`${docsDir}/${name}`);
13
13
  if (await src.exists()) {
14
14
  await Bun.write(`${outDir}/${name}`, src);
15
- return `/${name}`;
15
+ return `${baseUrl || ''}/${name}`.replace(/\/+/g, '/');
16
16
  }
17
17
  }
18
18
  }
@@ -32,7 +32,7 @@ export async function build(
32
32
  }
33
33
 
34
34
  const config = await loadConfig(docsDir);
35
- const logoSrc = await findLogo(docsDir, outDir);
35
+ const logoSrc = await findLogo(docsDir, outDir, config.baseUrl);
36
36
 
37
37
  const hasVersioning = config.versioning;
38
38
  const hasI18n = config.internationalization;
@@ -96,6 +96,7 @@ export async function build(
96
96
  currentVersion,
97
97
  currentLocale,
98
98
  translationOf: page.context.translationOf,
99
+ baseUrl: config.baseUrl,
99
100
  });
100
101
 
101
102
  const urlParts: string[] = [];
@@ -134,14 +135,14 @@ export async function build(
134
135
  const redirectHtml = `<!DOCTYPE html>
135
136
  <html>
136
137
  <head>
137
- <meta http-equiv="refresh" content="0; url=${redirectPath}">
138
- <script>window.location.href = "${redirectPath}";</script>
138
+ <meta http-equiv="refresh" content="0; url=${config.baseUrl || ''}${redirectPath}">
139
+ <script>window.location.href = "${config.baseUrl || ''}${redirectPath}";</script>
139
140
  </head>
140
141
  <body></body>
141
142
  </html>`;
142
143
  const outputPath = path.join(outDir, "index.html");
143
144
  await Bun.write(outputPath, redirectHtml);
144
- console.log(` / → ${path.relative(process.cwd(), outputPath)} (redirect to ${redirectPath})`);
145
+ console.log(` / → ${path.relative(process.cwd(), outputPath)} (redirect to ${config.baseUrl || ''}${redirectPath})`);
145
146
  }
146
147
 
147
148
  console.log(`\nDone! Built ${totalPages} pages to ${outDir}`);
package/src/config.ts CHANGED
@@ -1,11 +1,10 @@
1
- import yaml from "js-yaml";
2
1
  import type { Config } from "./types.ts";
3
2
 
4
3
  export async function loadConfig(docsDir: string): Promise<Config> {
5
4
  const file = Bun.file(`${docsDir}/lore.yml`);
6
5
  if (!(await file.exists())) return {};
7
6
  const text = await file.text();
8
- return (yaml.load(text) as Config) ?? {};
7
+ return (Bun.YAML.parse(text) as Config) ?? {};
9
8
  }
10
9
 
11
10
  // WCAG AA compliant colors (≥4.5:1 contrast on white)
package/src/parse.ts CHANGED
@@ -1,5 +1,3 @@
1
- import yaml from "js-yaml";
2
-
3
1
  export interface ParsedPage {
4
2
  frontmatter: Record<string, unknown>;
5
3
  content: string;
@@ -20,7 +18,7 @@ export function parsePage(raw: string): ParsedPage {
20
18
  if (end !== -1) {
21
19
  const fmText = content.slice(3, end).trim();
22
20
  if (fmText) {
23
- frontmatter = (yaml.load(fmText) as Record<string, unknown>) ?? {};
21
+ frontmatter = (Bun.YAML.parse(fmText) as Record<string, unknown>) ?? {};
24
22
  }
25
23
  content = content.slice(end + 4).trimStart();
26
24
  }
package/src/routing.ts CHANGED
@@ -31,10 +31,11 @@ export function parseUrl(url: string, config: Config): RouteContext {
31
31
 
32
32
  export function buildUrl(
33
33
  path: string,
34
- opts: { locale?: string; version?: string }
34
+ opts: { locale?: string; version?: string; baseUrl?: string }
35
35
  ): string {
36
36
  const parts: string[] = [];
37
37
 
38
+ if (opts.baseUrl) parts.push(opts.baseUrl.replace(/^\//, "").replace(/\/$/, ""));
38
39
  if (opts.locale) parts.push(opts.locale);
39
40
  if (opts.version) parts.push(opts.version);
40
41
 
package/src/template.ts CHANGED
@@ -12,14 +12,15 @@ function renderVersionSwitcher(
12
12
  versions: VersionInfo[],
13
13
  currentVersion: string | undefined,
14
14
  currentLocale: string | undefined,
15
- currentPath: string
15
+ currentPath: string,
16
+ baseUrl?: string
16
17
  ): string {
17
18
  if (!versions.length) return "";
18
19
 
19
20
  const items = versions
20
21
  .map((v) => {
21
22
  const isActive = v.name === currentVersion;
22
- const url = buildUrl(currentPath, { locale: currentLocale, version: v.name });
23
+ const url = buildUrl(currentPath, { locale: currentLocale, version: v.name, baseUrl });
23
24
  return `<option value="${url}"${isActive ? " selected" : ""}>${escHtml(v.label ?? v.name)}</option>`;
24
25
  })
25
26
  .join("");
@@ -33,14 +34,15 @@ function renderLanguageSwitcher(
33
34
  locales: LocaleInfo[],
34
35
  currentLocale: string | undefined,
35
36
  currentVersion: string | undefined,
36
- currentPath: string
37
+ currentPath: string,
38
+ baseUrl?: string
37
39
  ): string {
38
40
  if (!locales.length) return "";
39
41
 
40
42
  const items = locales
41
43
  .map((l) => {
42
44
  const isActive = l.code === currentLocale;
43
- const url = buildUrl(currentPath, { locale: l.code, version: currentVersion });
45
+ const url = buildUrl(currentPath, { locale: l.code, version: currentVersion, baseUrl });
44
46
  return `<option value="${url}"${isActive ? " selected" : ""}>${escHtml(l.label ?? getLocaleLabel(l.code))}</option>`;
45
47
  })
46
48
  .join("");
@@ -54,13 +56,14 @@ function sectionContainsUrl(
54
56
  items: SidebarItem[],
55
57
  url: string,
56
58
  locale?: string,
57
- version?: string
59
+ version?: string,
60
+ baseUrl?: string
58
61
  ): boolean {
59
- const prefix = buildUrl("", { locale, version });
62
+ const prefix = buildUrl("", { locale, version, baseUrl });
60
63
  for (const item of items) {
61
64
  if (item.type === "page" && prefix + item.url === url) return true;
62
65
  if (item.type === "section") {
63
- if (prefix + item.url === url || sectionContainsUrl(item.items, url, locale, version)) return true;
66
+ if (prefix + item.url === url || sectionContainsUrl(item.items, url, locale, version, baseUrl)) return true;
64
67
  }
65
68
  }
66
69
  return false;
@@ -70,9 +73,10 @@ function renderSidebarItems(
70
73
  items: SidebarItem[],
71
74
  currentUrl: string,
72
75
  locale?: string,
73
- version?: string
76
+ version?: string,
77
+ baseUrl?: string
74
78
  ): string {
75
- const prefix = buildUrl("", { locale, version });
79
+ const prefix = buildUrl("", { locale, version, baseUrl });
76
80
  const hasPrefix = prefix !== "/";
77
81
 
78
82
  return items
@@ -92,13 +96,13 @@ function renderSidebarItems(
92
96
  const active = item.url === currentUrl;
93
97
  return `<li><a href="${url}" class="sidebar-row${active ? " active" : ""}">${escHtml(item.title)}</a></li>`;
94
98
  } else {
95
- const open = sectionContainsUrl(item.items, currentUrl, locale, version) || item.url === currentUrl;
99
+ const open = sectionContainsUrl(item.items, currentUrl, locale, version, baseUrl) || item.url === currentUrl;
96
100
  const active = item.url === currentUrl;
97
101
  const titleEl = item.url
98
102
  ? `<a href="${url}" class="section-link">${escHtml(item.title)}</a>`
99
103
  : `<span class="section-link">${escHtml(item.title)}</span>`;
100
104
  const inner = item.items.length > 0
101
- ? `<ul class="section-items">${renderSidebarItems(item.items, currentUrl, locale, version)}</ul>`
105
+ ? `<ul class="section-items">${renderSidebarItems(item.items, currentUrl, locale, version, baseUrl)}</ul>`
102
106
  : "";
103
107
  return `<li class="section${open ? " open" : ""}" data-section="${escHtml(item.title)}">
104
108
  <div class="sidebar-row${active ? " active" : ""}">
@@ -157,6 +161,7 @@ export interface PageTemplateOptions {
157
161
  currentVersion?: string;
158
162
  currentLocale?: string;
159
163
  translationOf?: string;
164
+ baseUrl?: string;
160
165
  }
161
166
 
162
167
  export function renderPage(opts: PageTemplateOptions): string {
@@ -174,10 +179,11 @@ export function renderPage(opts: PageTemplateOptions): string {
174
179
  currentVersion,
175
180
  currentLocale,
176
181
  translationOf,
182
+ baseUrl,
177
183
  } = opts;
178
184
 
179
185
  const accent = resolveColor(config.color);
180
- const homeUrl = buildUrl("", { locale: currentLocale, version: currentVersion });
186
+ const homeUrl = buildUrl("", { locale: currentLocale, version: currentVersion, baseUrl });
181
187
  const siteTitle = config.title ?? "Docs";
182
188
  const pageTitle = title ? `${title} — ${siteTitle}` : siteTitle;
183
189
  const metaDesc = description ?? config.description ?? "";
@@ -225,8 +231,8 @@ export function renderPage(opts: PageTemplateOptions): string {
225
231
  <a href="${escHtml(homeUrl)}" class="logo">${logoSrc ? `<img src="${escHtml(logoSrc)}" alt="" width="24" height="24" class="logo-img">` : ""}${escHtml(siteTitle)}</a>
226
232
  </div>
227
233
  <div class="header-right">
228
- ${renderVersionSwitcher(versions ?? [], currentVersion, currentLocale, currentUrl)}
229
- ${renderLanguageSwitcher(locales ?? [], currentLocale, currentVersion, currentUrl)}
234
+ ${renderVersionSwitcher(versions ?? [], currentVersion, currentLocale, currentUrl, baseUrl)}
235
+ ${renderLanguageSwitcher(locales ?? [], currentLocale, currentVersion, currentUrl, baseUrl)}
230
236
  <nav class="header-links">
231
237
  ${renderHeaderLinks(config.links)}
232
238
  </nav>
@@ -244,7 +250,7 @@ export function renderPage(opts: PageTemplateOptions): string {
244
250
  <aside class="sidebar">
245
251
  <nav>
246
252
  <ul class="sidebar-nav">
247
- ${renderSidebarItems(sidebar, currentUrl, currentLocale, currentVersion)}
253
+ ${renderSidebarItems(sidebar, currentUrl, currentLocale, currentVersion, baseUrl)}
248
254
  </ul>
249
255
  </nav>
250
256
  </aside>
package/src/types.ts CHANGED
@@ -8,6 +8,7 @@ export interface Config {
8
8
  internationalization?: boolean;
9
9
  defaultVersion?: string;
10
10
  defaultLocale?: string;
11
+ baseUrl?: string;
11
12
  }
12
13
 
13
14
  export interface VersionInfo {