mordoc 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mordoc",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A modern documentation site generator powered by Vite, React, and Markdoc.",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,11 +1,44 @@
1
+ import type { LanguageConfig } from '../types/language.js';
2
+
1
3
  /**
2
- * Re-exports all lang utilities from the shared `src/utils/lang-utils.ts`.
3
- * The shared location is importable by both the React app and Node-side code
4
- * (pipeline, SSG runner). App-side imports continue to use this path unchanged.
4
+ * Lang utilities for the React app. Self-contained so that src/app/ has no
5
+ * imports outside its own directory required for it to work as a published
6
+ * npm artifact compiled by the user's Vite. Node-side code uses the copy in
7
+ * src/utils/lang-utils.ts compiled to dist/.
5
8
  */
6
- export {
7
- detectCurrentLang,
8
- buildLangPrefix,
9
- stripLangPrefix,
10
- resolveLabel,
11
- } from '../utils/lang-utils.js';
9
+
10
+ export function detectCurrentLang(
11
+ pathname: string,
12
+ language: LanguageConfig | null,
13
+ defaultLanguage: string,
14
+ ): string {
15
+ if (!language || language.languages.length <= 1) return defaultLanguage;
16
+ const firstSegment = pathname.split('/').filter(Boolean)[0] ?? '';
17
+ const nonDefault = language.languages.filter((l) => l !== defaultLanguage);
18
+ return nonDefault.includes(firstSegment) ? firstSegment : defaultLanguage;
19
+ }
20
+
21
+ export function buildLangPrefix(lang: string, defaultLanguage: string): string {
22
+ return lang === defaultLanguage ? '' : `/${lang}`;
23
+ }
24
+
25
+ export function stripLangPrefix(
26
+ pathname: string,
27
+ lang: string,
28
+ defaultLanguage: string,
29
+ ): string {
30
+ if (lang === defaultLanguage) return pathname;
31
+ const prefix = `/${lang}`;
32
+ const stripped = pathname.startsWith(prefix) ? pathname.slice(prefix.length) : pathname;
33
+ return stripped || '/';
34
+ }
35
+
36
+ export function resolveLabel(
37
+ defaultLabel: string,
38
+ lang: string,
39
+ defaultLanguage: string,
40
+ translations: Record<string, Record<string, string>>,
41
+ ): string {
42
+ if (lang === defaultLanguage) return defaultLabel;
43
+ return translations[lang]?.[defaultLabel] ?? defaultLabel;
44
+ }