mdorigin 0.5.0 → 0.5.2

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 CHANGED
@@ -23,7 +23,7 @@ That means `mdorigin` should own content semantics, while page rendering remains
23
23
  - extensionless routes render human-friendly HTML from the same files
24
24
  - `README.md`, `index.md`, and `SKILL.md` all fit into one routing model
25
25
  - the same core works in local preview and Cloudflare Workers
26
- - optional search is powered by [`indexbind`](https://github.com/jolestar/indexbind)
26
+ - optional search is powered by [`indexbind`](https://github.com/holon-run/indexbind)
27
27
 
28
28
  ## Install
29
29
 
@@ -87,7 +87,7 @@ The intended boundary is:
87
87
 
88
88
  ## Optional Search
89
89
 
90
- `mdorigin` can build a local retrieval bundle through the optional [`indexbind`](https://github.com/jolestar/indexbind) package. For the retrieval engine itself, see the `indexbind` docs: <https://indexbind.jolestar.workers.dev>.
90
+ `mdorigin` can build a local retrieval bundle through the optional [`indexbind`](https://github.com/holon-run/indexbind) package. For the retrieval engine itself, see the `indexbind` docs: <https://indexbind.jolestar.workers.dev>.
91
91
 
92
92
  ```bash
93
93
  npm install indexbind
@@ -127,7 +127,7 @@ Runtime endpoints:
127
127
 
128
128
  ## Docs
129
129
 
130
- - Docs site: <https://mdorigin.jolestar.workers.dev>
130
+ - Docs site: <https://mdorigin.holon.run>
131
131
  - Getting started: [`docs/site/guides/getting-started.md`](docs/site/guides/getting-started.md)
132
132
  - Routing model: [`docs/site/concepts/routing.md`](docs/site/concepts/routing.md)
133
133
  - Directory indexes: [`docs/site/concepts/directory-indexes.md`](docs/site/concepts/directory-indexes.md)
@@ -136,4 +136,4 @@ Runtime endpoints:
136
136
  - Search setup: [`docs/site/guides/getting-started.md`](docs/site/guides/getting-started.md#quick-start)
137
137
  - Cloudflare deployment: [`docs/site/guides/cloudflare.md`](docs/site/guides/cloudflare.md)
138
138
 
139
- The docs site at <https://mdorigin.jolestar.workers.dev> is deployed automatically from `main` with GitHub Actions.
139
+ The docs site at <https://mdorigin.holon.run> is deployed automatically from `main` with GitHub Actions.
@@ -48,6 +48,8 @@ export function createCloudflareWorker(manifest, options = {}) {
48
48
  siteConfig: manifest.siteConfig ?? {
49
49
  siteTitle: 'mdorigin',
50
50
  siteUrl: undefined,
51
+ locale: 'en',
52
+ messages: {},
51
53
  favicon: undefined,
52
54
  logo: undefined,
53
55
  showDate: true,
@@ -23,6 +23,9 @@ export async function runBuildIndexCommand(argv) {
23
23
  rootDir,
24
24
  dir,
25
25
  plugins: loadedConfig.plugins,
26
+ excludedDirectories: (loadedConfig.siteConfig.locales ?? [])
27
+ .filter((locale) => locale.contentBase !== '')
28
+ .map((locale) => locale.contentBase),
26
29
  });
27
30
  console.log(`updated ${result.updatedFiles.length} index file(s)`);
28
31
  if (result.skippedDirectories.length > 0) {
@@ -8,10 +8,23 @@ export interface IndexTransformContext {
8
8
  sourcePath?: string;
9
9
  siteConfig?: ResolvedSiteConfig;
10
10
  }
11
+ export interface PageLanguage {
12
+ code: string;
13
+ label: string;
14
+ /** Root-relative href for this language: the translated page when available, otherwise the language home. */
15
+ href: string;
16
+ current: boolean;
17
+ /** Whether a page-level translation exists for this language. */
18
+ translated: boolean;
19
+ }
11
20
  export interface PageRenderModel {
12
21
  kind: 'page' | 'listing';
13
22
  requestPath: string;
14
23
  sourcePath: string;
24
+ /** Effective UI locale for this request (frontmatter overrides not applied). */
25
+ locale: string;
26
+ /** Language switcher entries; empty for single-language sites. */
27
+ languages: PageLanguage[];
15
28
  siteTitle: string;
16
29
  siteDescription?: string;
17
30
  siteUrl?: string;
@@ -6,11 +6,17 @@ import { extractManagedIndexEntries, getDocumentSummary, getDocumentTitle as get
6
6
  import { ensureTrailingSlash, trimLeadingSlash } from './site-url.js';
7
7
  import { applyIndexTransforms, renderFooterOverride, renderHeaderOverride, renderPageWithPlugins, transformHtmlWithPlugins, } from './extensions.js';
8
8
  import { handleApiRoute } from './api.js';
9
- import { normalizeRequestPath, resolveRequest } from './router.js';
9
+ import { matchRequestLocale, normalizeRequestPath, resolveRequest } from './router.js';
10
10
  import { escapeHtml, renderListingArticleItems, renderDocument, } from '../html/template.js';
11
+ import { formatSiteMessage, resolveSiteMessages, } from '../i18n/messages.js';
11
12
  export async function handleSiteRequest(store, pathname, options) {
12
13
  const plugins = options.plugins ?? [];
13
14
  const searchEnabled = options.searchApi !== undefined;
15
+ const requestLocale = matchRequestLocale(pathname, options.siteConfig.locales);
16
+ const defaultLocale = options.siteConfig.locales?.find((locale) => locale.isDefault);
17
+ if (defaultLocale !== undefined && defaultLocale.pathPrefix !== '' && pathname === '/') {
18
+ return redirect(`${defaultLocale.pathPrefix}/`);
19
+ }
14
20
  const apiRoute = await handleApiRoute(pathname, options.searchParams, {
15
21
  searchApi: options.searchApi,
16
22
  siteConfig: options.siteConfig,
@@ -23,7 +29,14 @@ export async function handleSiteRequest(store, pathname, options) {
23
29
  return renderSitemap(store, options);
24
30
  }
25
31
  if (pathname === '/feed.xml') {
26
- return renderRssFeed(store, options);
32
+ return renderRssFeed(store, options, defaultLocale ?? null);
33
+ }
34
+ if (options.siteConfig.locales !== undefined && requestLocale !== null) {
35
+ for (const locale of options.siteConfig.locales) {
36
+ if (locale.pathPrefix !== '' && pathname === `${locale.pathPrefix}/feed.xml`) {
37
+ return renderRssFeed(store, options, locale);
38
+ }
39
+ }
27
40
  }
28
41
  const resolved = resolveRequest(pathname);
29
42
  const listingFragmentRequest = getListingFragmentRequest(options.searchParams);
@@ -58,20 +71,20 @@ export async function handleSiteRequest(store, pathname, options) {
58
71
  if (directoryIndexResponse !== null) {
59
72
  return directoryIndexResponse;
60
73
  }
61
- return renderDirectoryListing(store, resolved.requestPath, options.siteConfig, searchEnabled);
74
+ return renderDirectoryListing(store, resolved.requestPath, options.siteConfig, searchEnabled, requestLocale);
62
75
  }
63
- return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown);
76
+ return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown, requestLocale);
64
77
  }
65
78
  if (resolved.kind === 'asset') {
66
79
  return serveAsset(entry);
67
80
  }
68
81
  if (entry.kind !== 'text' || entry.text === undefined) {
69
- return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown);
82
+ return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown, requestLocale);
70
83
  }
71
84
  if (resolved.kind === 'markdown' || negotiatedMarkdown) {
72
85
  const parsed = await parseMarkdownDocument(resolved.sourcePath, entry.text);
73
86
  if (parsed.meta.draft === true && options.draftMode === 'exclude') {
74
- return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown);
87
+ return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown, requestLocale);
75
88
  }
76
89
  return {
77
90
  status: 200,
@@ -83,9 +96,9 @@ export async function handleSiteRequest(store, pathname, options) {
83
96
  }
84
97
  const parsed = await parseMarkdownDocument(resolved.sourcePath, entry.text);
85
98
  if (parsed.meta.draft === true && options.draftMode === 'exclude') {
86
- return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown);
99
+ return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown, requestLocale);
87
100
  }
88
- const navigation = await resolveTopNav(store, options.siteConfig);
101
+ const navigation = await resolveTopNav(store, options.siteConfig, requestLocale);
89
102
  const renderedBody = isRootHomeRequest(resolved.requestPath) && !options.siteConfig.showHomeIndex
90
103
  ? stripManagedIndexBlock(entry.text)
91
104
  : isRootHomeRequest(resolved.requestPath) && navigation.items.length > 0
@@ -114,6 +127,9 @@ export async function handleSiteRequest(store, pathname, options) {
114
127
  listingEntries,
115
128
  searchEnabled,
116
129
  plugins,
130
+ store,
131
+ requestLocale,
132
+ draftMode: options.draftMode,
117
133
  varyOnAccept: shouldVaryOnAccept(resolved),
118
134
  });
119
135
  }
@@ -148,8 +164,10 @@ function buildPageRenderModel(options) {
148
164
  kind: options.listingEntries.length > 0 ? 'listing' : 'page',
149
165
  requestPath: options.resolvedRequestPath,
150
166
  sourcePath: options.sourcePath,
151
- siteTitle: options.siteConfig.siteTitle,
152
- siteDescription: options.siteConfig.siteDescription,
167
+ locale: options.locale,
168
+ languages: options.languages,
169
+ siteTitle: options.siteTitle ?? options.siteConfig.siteTitle,
170
+ siteDescription: options.siteDescription ?? options.siteConfig.siteDescription,
153
171
  siteUrl: options.siteConfig.siteUrl,
154
172
  favicon: options.siteConfig.favicon,
155
173
  socialImage: options.siteConfig.socialImage,
@@ -164,7 +182,7 @@ function buildPageRenderModel(options) {
164
182
  showSummary: options.siteConfig.showSummary,
165
183
  showDate: options.siteConfig.showDate,
166
184
  topNav: options.topNav,
167
- footerNav: options.siteConfig.footerNav,
185
+ footerNav: options.footerNav ?? options.siteConfig.footerNav,
168
186
  footerText: options.siteConfig.footerText,
169
187
  socialLinks: options.siteConfig.socialLinks,
170
188
  editLink: options.siteConfig.editLink,
@@ -180,12 +198,24 @@ function buildPageRenderModel(options) {
180
198
  };
181
199
  }
182
200
  async function renderStructuredPage(options) {
201
+ const localeConfig = options.requestLocale;
202
+ const localeCode = localeConfig?.code ?? options.siteConfig.locale;
203
+ const messages = getEffectiveLocaleMessages(options.siteConfig, localeConfig);
204
+ const htmlLang = getFrontmatterLocale(options.parsed.meta) ?? localeCode;
205
+ const languages = await buildLanguageOptions(options.store, { sourcePath: options.sourcePath }, localeConfig, options.siteConfig, options.draftMode);
206
+ const hreflangAlternates = buildHreflangAlternates(languages, options.siteConfig);
207
+ const searchLocaleFilter = buildSearchLocaleFilter(options.siteConfig, localeConfig);
183
208
  const page = buildPageRenderModel({
184
209
  resolvedRequestPath: options.requestPath,
185
210
  sourcePath: options.sourcePath,
211
+ locale: localeCode,
212
+ languages,
186
213
  renderedBodyHtml: options.renderedParsed.html,
187
214
  parsed: options.parsed,
188
215
  siteConfig: options.siteConfig,
216
+ siteTitle: getEffectiveSiteTitle(options.siteConfig, localeConfig),
217
+ siteDescription: getEffectiveSiteDescription(options.siteConfig, localeConfig),
218
+ footerNav: getEffectiveFooterNav(options.siteConfig, localeConfig),
189
219
  topNav: options.topNav,
190
220
  listingEntries: options.listingEntries,
191
221
  searchEnabled: options.searchEnabled,
@@ -204,6 +234,8 @@ async function renderStructuredPage(options) {
204
234
  return renderDocument({
205
235
  siteTitle: currentPage.siteTitle,
206
236
  siteDescription: currentPage.siteDescription,
237
+ locale: htmlLang,
238
+ messages,
207
239
  siteUrl: currentPage.siteUrl,
208
240
  favicon: currentPage.favicon,
209
241
  socialImage: currentPage.socialImage,
@@ -222,12 +254,15 @@ async function renderStructuredPage(options) {
222
254
  stylesheetContent: currentPage.stylesheetContent,
223
255
  canonicalPath: currentPage.canonicalPath,
224
256
  alternateMarkdownPath: currentPage.alternateMarkdownPath,
225
- rssFeedUrl: getRssFeedUrl(currentPage.siteUrl, options.siteConfig),
257
+ rssFeedUrl: getRssFeedUrl(currentPage.siteUrl, options.siteConfig, localeConfig),
226
258
  listingEntries: currentPage.listingEntries,
227
259
  listingRequestPath: currentPage.listingRequestPath,
228
260
  listingInitialPostCount: currentPage.listingInitialPostCount,
229
261
  listingLoadMoreStep: currentPage.listingLoadMoreStep,
230
262
  searchEnabled: currentPage.searchEnabled,
263
+ languages: currentPage.languages,
264
+ hreflangAlternates,
265
+ searchLocaleFilter,
231
266
  headerHtml,
232
267
  footerHtml,
233
268
  });
@@ -292,20 +327,26 @@ function notFound() {
292
327
  }
293
328
  async function renderNotFoundForRequest(store, pathname, options) {
294
329
  const resolved = resolveRequest(pathname);
295
- return renderNotFoundForResolvedRequest(store, resolved, options, false);
330
+ return renderNotFoundForResolvedRequest(store, resolved, options, false, matchRequestLocale(pathname, options.siteConfig.locales));
296
331
  }
297
- async function renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown) {
332
+ async function renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown, requestLocale) {
298
333
  const varyOnAccept = shouldVaryOnAccept(resolved);
299
334
  if (resolved.kind !== 'html' || negotiatedMarkdown) {
300
335
  return withNotFoundVary(varyOnAccept);
301
336
  }
302
- return renderHtmlNotFound(store, resolved.requestPath, options, varyOnAccept);
337
+ return renderHtmlNotFound(store, resolved.requestPath, options, varyOnAccept, requestLocale);
303
338
  }
304
- async function renderHtmlNotFound(store, requestPath, options, varyOnAccept) {
305
- const navigation = await resolveTopNav(store, options.siteConfig);
339
+ async function renderHtmlNotFound(store, requestPath, options, varyOnAccept, requestLocale) {
340
+ const localeConfig = requestLocale;
341
+ const navigation = await resolveTopNav(store, options.siteConfig, localeConfig);
342
+ const locale = localeConfig?.code ?? options.siteConfig.locale;
343
+ const messages = getEffectiveLocaleMessages(options.siteConfig, localeConfig);
344
+ const languages = await buildLanguageOptions(store, {}, localeConfig, options.siteConfig, options.draftMode);
306
345
  const body = [
307
- '<h1>Not Found</h1>',
308
- `<p>No page was published at <code>${escapeHtml(requestPath)}</code>.</p>`,
346
+ `<h1>${escapeHtml(messages['error.notFoundTitle'])}</h1>`,
347
+ `<p>${formatSiteMessage(messages['error.notFoundBody'], {
348
+ path: escapeHtml(requestPath),
349
+ })}</p>`,
309
350
  ].join('');
310
351
  return {
311
352
  status: 404,
@@ -313,22 +354,25 @@ async function renderHtmlNotFound(store, requestPath, options, varyOnAccept) {
313
354
  'content-type': 'text/html; charset=utf-8',
314
355
  }, varyOnAccept),
315
356
  body: renderDocument({
316
- siteTitle: options.siteConfig.siteTitle,
317
- siteDescription: options.siteConfig.siteDescription,
357
+ siteTitle: getEffectiveSiteTitle(options.siteConfig, localeConfig),
358
+ siteDescription: getEffectiveSiteDescription(options.siteConfig, localeConfig),
318
359
  siteUrl: options.siteConfig.siteUrl,
319
360
  favicon: options.siteConfig.favicon,
320
361
  socialImage: options.siteConfig.socialImage,
321
362
  logo: options.siteConfig.logo,
322
- title: 'Not Found',
363
+ title: messages['error.notFoundTitle'],
323
364
  body,
365
+ locale,
366
+ messages,
367
+ languages,
324
368
  showSummary: false,
325
369
  showDate: false,
326
370
  topNav: navigation.items,
327
- footerNav: options.siteConfig.footerNav,
371
+ footerNav: getEffectiveFooterNav(options.siteConfig, localeConfig),
328
372
  footerText: options.siteConfig.footerText,
329
373
  socialLinks: options.siteConfig.socialLinks,
330
374
  stylesheetContent: options.siteConfig.stylesheetContent,
331
- rssFeedUrl: getRssFeedUrl(options.siteConfig.siteUrl, options.siteConfig),
375
+ rssFeedUrl: getRssFeedUrl(options.siteConfig.siteUrl, options.siteConfig, localeConfig),
332
376
  searchEnabled: options.searchApi !== undefined,
333
377
  }),
334
378
  };
@@ -352,6 +396,139 @@ function redirect(location) {
352
396
  },
353
397
  };
354
398
  }
399
+ function getEffectiveLocaleMessages(siteConfig, localeConfig) {
400
+ if (localeConfig === null) {
401
+ return resolveSiteMessages(siteConfig.locale, siteConfig.messages);
402
+ }
403
+ return resolveSiteMessages(localeConfig.code, {
404
+ ...siteConfig.messages,
405
+ ...localeConfig.messages,
406
+ });
407
+ }
408
+ function getEffectiveSiteTitle(siteConfig, localeConfig) {
409
+ return localeConfig?.siteTitle ?? siteConfig.siteTitle;
410
+ }
411
+ function getEffectiveSiteDescription(siteConfig, localeConfig) {
412
+ return localeConfig?.siteDescription ?? siteConfig.siteDescription;
413
+ }
414
+ function getEffectiveFooterNav(siteConfig, localeConfig) {
415
+ if (localeConfig !== null && (localeConfig.footerNav?.length ?? 0) > 0) {
416
+ return localeConfig.footerNav;
417
+ }
418
+ return siteConfig.footerNav;
419
+ }
420
+ function getFrontmatterLocale(meta) {
421
+ if (typeof meta.lang !== 'string') {
422
+ return null;
423
+ }
424
+ const trimmed = meta.lang.trim();
425
+ return trimmed === '' ? null : trimmed;
426
+ }
427
+ async function buildLanguageOptions(store, target, currentLocale, siteConfig, draftMode) {
428
+ const locales = siteConfig.locales;
429
+ if (locales === undefined || locales.length === 0) {
430
+ return [];
431
+ }
432
+ const languages = [];
433
+ for (const locale of locales) {
434
+ const translated = await localeHasContent(store, target, currentLocale, locale, draftMode);
435
+ languages.push({
436
+ code: locale.code,
437
+ label: locale.label,
438
+ href: translated === null
439
+ ? getLocaleHomePath(locale)
440
+ : getCanonicalHtmlPathForContentPath(translated),
441
+ current: locale === currentLocale,
442
+ translated: translated !== null,
443
+ });
444
+ }
445
+ return languages;
446
+ }
447
+ async function localeHasContent(store, target, currentLocale, locale, draftMode) {
448
+ if (locale === currentLocale) {
449
+ return target.sourcePath
450
+ ? target.sourcePath
451
+ : target.directoryPath === ''
452
+ ? 'index.md'
453
+ : `${target.directoryPath}/index.md`;
454
+ }
455
+ const candidates = [];
456
+ if (target.sourcePath !== undefined) {
457
+ candidates.push(mapContentPathForLocale(target.sourcePath, currentLocale, locale));
458
+ }
459
+ else {
460
+ const directoryPath = target.directoryPath ?? '';
461
+ for (const candidate of getDirectoryIndexCandidates(mapContentPathForLocale(directoryPath, currentLocale, locale))) {
462
+ candidates.push(candidate);
463
+ }
464
+ }
465
+ for (const candidate of candidates) {
466
+ if (await hasPublishedContent(store, candidate, draftMode)) {
467
+ return candidate;
468
+ }
469
+ }
470
+ return null;
471
+ }
472
+ function mapContentPathForLocale(contentPath, from, to) {
473
+ if (from === null || from.contentBase === '') {
474
+ return to.contentBase === '' ? contentPath : `${to.contentBase}/${contentPath}`;
475
+ }
476
+ if (!contentPath.startsWith(`${from.contentBase}/`)) {
477
+ return contentPath;
478
+ }
479
+ const rest = contentPath.slice(from.contentBase.length + 1);
480
+ return to.contentBase === '' ? rest : `${to.contentBase}/${rest}`;
481
+ }
482
+ function getLocaleHomePath(locale) {
483
+ return locale.pathPrefix === '' ? '/' : `${locale.pathPrefix}/`;
484
+ }
485
+ async function hasPublishedContent(store, contentPath, draftMode) {
486
+ const entry = await store.get(contentPath);
487
+ if (entry === null || entry.kind !== 'text' || entry.text === undefined) {
488
+ return false;
489
+ }
490
+ if (draftMode === 'exclude') {
491
+ const parsed = await parseMarkdownDocument(contentPath, entry.text);
492
+ if (parsed.meta.draft === true) {
493
+ return false;
494
+ }
495
+ }
496
+ return true;
497
+ }
498
+ function buildHreflangAlternates(languages, siteConfig) {
499
+ if (languages.length === 0 || siteConfig.siteUrl === undefined) {
500
+ return [];
501
+ }
502
+ const base = ensureTrailingSlash(siteConfig.siteUrl);
503
+ const alternates = languages
504
+ .filter((language) => language.translated)
505
+ .map((language) => ({
506
+ hreflang: language.code,
507
+ href: new URL(trimLeadingSlash(language.href), base).toString(),
508
+ }));
509
+ const defaultLocale = siteConfig.locales?.find((locale) => locale.isDefault);
510
+ const defaultLanguage = defaultLocale
511
+ ? languages.find((language) => language.code === defaultLocale.code)
512
+ : undefined;
513
+ if (defaultLanguage?.translated) {
514
+ alternates.push({
515
+ hreflang: 'x-default',
516
+ href: new URL(trimLeadingSlash(defaultLanguage.href), base).toString(),
517
+ });
518
+ }
519
+ return alternates;
520
+ }
521
+ function buildSearchLocaleFilter(siteConfig, localeConfig) {
522
+ if (siteConfig.locales === undefined || localeConfig === null) {
523
+ return undefined;
524
+ }
525
+ return {
526
+ include: localeConfig.contentBase === '' ? '' : `${localeConfig.contentBase}/`,
527
+ exclude: siteConfig.locales
528
+ .filter((locale) => locale !== localeConfig && locale.contentBase !== '')
529
+ .map((locale) => `${locale.contentBase}/`),
530
+ };
531
+ }
355
532
  async function renderSitemap(store, options) {
356
533
  if (!options.siteConfig.siteUrl) {
357
534
  return {
@@ -380,15 +557,19 @@ async function renderSitemap(store, options) {
380
557
  body,
381
558
  };
382
559
  }
383
- async function renderRssFeed(store, options) {
560
+ async function renderRssFeed(store, options, locale) {
384
561
  if (!isRssEnabled(options.siteConfig) || !options.siteConfig.siteUrl) {
385
562
  return notFound();
386
563
  }
387
- const items = await collectRssFeedItems(store, '', options);
564
+ const excludedLocaleDirectories = new Set((options.siteConfig.locales ?? [])
565
+ .filter((entry) => entry.contentBase !== '' && entry !== locale)
566
+ .map((entry) => entry.contentBase));
567
+ const items = await collectRssFeedItems(store, locale?.contentBase ?? '', options, excludedLocaleDirectories);
388
568
  const limitedItems = items.slice(0, options.siteConfig.rss?.maxItems ?? 20);
389
- const rssFeedUrl = getRssFeedUrl(options.siteConfig.siteUrl, options.siteConfig);
390
- const title = options.siteConfig.rss?.title ?? options.siteConfig.siteTitle;
391
- const description = options.siteConfig.rss?.description ?? options.siteConfig.siteDescription;
569
+ const rssFeedUrl = getRssFeedUrl(options.siteConfig.siteUrl, options.siteConfig, locale);
570
+ const title = options.siteConfig.rss?.title ?? getEffectiveSiteTitle(options.siteConfig, locale);
571
+ const description = options.siteConfig.rss?.description ??
572
+ getEffectiveSiteDescription(options.siteConfig, locale);
392
573
  const lastBuildDate = limitedItems[0]?.pubDate.toUTCString();
393
574
  const body = [
394
575
  '<?xml version="1.0" encoding="UTF-8"?>',
@@ -503,7 +684,7 @@ function dedupeSitemapEntries(entries) {
503
684
  }
504
685
  return Array.from(deduped.values());
505
686
  }
506
- async function collectRssFeedItems(store, directoryPath, options) {
687
+ async function collectRssFeedItems(store, directoryPath, options, excludedDirectories) {
507
688
  const entries = await store.listDirectory(directoryPath);
508
689
  if (entries === null) {
509
690
  return [];
@@ -512,7 +693,10 @@ async function collectRssFeedItems(store, directoryPath, options) {
512
693
  const directoryShape = inspectDirectoryShapeEntries(entries);
513
694
  for (const entry of entries) {
514
695
  if (entry.kind === 'directory') {
515
- feedItems.push(...(await collectRssFeedItems(store, entry.path, options)));
696
+ if (excludedDirectories.has(entry.path)) {
697
+ continue;
698
+ }
699
+ feedItems.push(...(await collectRssFeedItems(store, entry.path, options, excludedDirectories)));
516
700
  continue;
517
701
  }
518
702
  if (!isMarkdownEntry(entry)) {
@@ -571,20 +755,25 @@ function parseFeedDate(value) {
571
755
  const parsed = new Date(value);
572
756
  return Number.isNaN(parsed.getTime()) ? null : parsed;
573
757
  }
574
- async function renderDirectoryListing(store, requestPath, siteConfig, searchEnabled) {
758
+ async function renderDirectoryListing(store, requestPath, siteConfig, searchEnabled, requestLocale) {
575
759
  const directoryPath = requestPath === '/' ? '' : requestPath.slice(1).replace(/\/$/, '');
576
760
  const entries = await store.listDirectory(directoryPath);
577
761
  if (entries === null) {
578
762
  return notFound();
579
763
  }
580
764
  const visibleEntries = entries.filter(isVisibleDirectoryEntry);
581
- const navigation = await resolveTopNav(store, siteConfig);
765
+ const locale = requestLocale?.code ?? siteConfig.locale;
766
+ const navigation = await resolveTopNav(store, siteConfig, requestLocale);
767
+ const messages = getEffectiveLocaleMessages(siteConfig, requestLocale);
768
+ const languages = await buildLanguageOptions(store, { directoryPath }, requestLocale, siteConfig, 'exclude');
582
769
  const listItems = visibleEntries
583
770
  .map((entry) => `<li><a href="${getDirectoryEntryHref(requestPath, entry)}">${escapeHtml(getDirectoryEntryLabel(entry))}</a></li>`)
584
771
  .join('');
585
772
  const body = [
586
773
  `<h1>${escapeHtml(getDirectoryTitle(requestPath))}</h1>`,
587
- visibleEntries.length > 0 ? `<ul>${listItems}</ul>` : '<p>This directory is empty.</p>',
774
+ visibleEntries.length > 0
775
+ ? `<ul>${listItems}</ul>`
776
+ : `<p>${escapeHtml(messages['listing.emptyDirectory'])}</p>`,
588
777
  ].join('');
589
778
  return {
590
779
  status: 200,
@@ -592,8 +781,11 @@ async function renderDirectoryListing(store, requestPath, siteConfig, searchEnab
592
781
  'content-type': 'text/html; charset=utf-8',
593
782
  },
594
783
  body: renderDocument({
595
- siteTitle: siteConfig.siteTitle,
596
- siteDescription: siteConfig.siteDescription,
784
+ siteTitle: getEffectiveSiteTitle(siteConfig, requestLocale),
785
+ siteDescription: getEffectiveSiteDescription(siteConfig, requestLocale),
786
+ locale,
787
+ messages,
788
+ languages,
597
789
  siteUrl: siteConfig.siteUrl,
598
790
  favicon: siteConfig.favicon,
599
791
  logo: siteConfig.logo,
@@ -602,13 +794,13 @@ async function renderDirectoryListing(store, requestPath, siteConfig, searchEnab
602
794
  showSummary: false,
603
795
  showDate: false,
604
796
  topNav: navigation.items,
605
- footerNav: siteConfig.footerNav,
797
+ footerNav: getEffectiveFooterNav(siteConfig, requestLocale),
606
798
  footerText: siteConfig.footerText,
607
799
  socialLinks: siteConfig.socialLinks,
608
800
  stylesheetContent: siteConfig.stylesheetContent,
609
801
  canonicalPath: requestPath,
610
802
  alternateMarkdownPath: getMarkdownRequestPathForContentPath(getDirectoryIndexContentPathForRequestPath(requestPath)),
611
- rssFeedUrl: getRssFeedUrl(siteConfig.siteUrl, siteConfig),
803
+ rssFeedUrl: getRssFeedUrl(siteConfig.siteUrl, siteConfig, requestLocale),
612
804
  searchEnabled,
613
805
  }),
614
806
  };
@@ -654,7 +846,8 @@ async function tryRenderAlternateDirectoryIndex(store, requestPath, options) {
654
846
  if (parsed.meta.draft === true && options.draftMode === 'exclude') {
655
847
  return notFound();
656
848
  }
657
- const navigation = await resolveTopNav(store, options.siteConfig);
849
+ const requestLocale = matchRequestLocale(requestPath, options.siteConfig.locales);
850
+ const navigation = await resolveTopNav(store, options.siteConfig, requestLocale);
658
851
  const renderedBody = isRootHomeRequest(requestPath) && !options.siteConfig.showHomeIndex
659
852
  ? stripManagedIndexBlock(entry.text)
660
853
  : isRootHomeRequest(requestPath) && navigation.items.length > 0
@@ -684,6 +877,9 @@ async function tryRenderAlternateDirectoryIndex(store, requestPath, options) {
684
877
  listingEntries,
685
878
  searchEnabled: options.searchApi !== undefined,
686
879
  plugins,
880
+ store,
881
+ requestLocale,
882
+ draftMode: options.draftMode,
687
883
  });
688
884
  }
689
885
  return null;
@@ -859,11 +1055,14 @@ function getCanonicalHtmlPathForContentPath(contentPath) {
859
1055
  function isRssEnabled(siteConfig) {
860
1056
  return Boolean(siteConfig.siteUrl) && (siteConfig.rss?.enabled ?? true);
861
1057
  }
862
- function getRssFeedUrl(siteUrl, siteConfig) {
1058
+ function getRssFeedUrl(siteUrl, siteConfig, locale) {
863
1059
  if (!siteUrl || !isRssEnabled(siteConfig)) {
864
1060
  return undefined;
865
1061
  }
866
- return new URL('feed.xml', ensureTrailingSlash(siteUrl)).toString();
1062
+ const feedPath = locale !== null && locale.pathPrefix !== ''
1063
+ ? `${locale.pathPrefix.slice(1)}/feed.xml`
1064
+ : 'feed.xml';
1065
+ return new URL(feedPath, ensureTrailingSlash(siteUrl)).toString();
867
1066
  }
868
1067
  function getEditLinkHref(siteConfig, sourcePath) {
869
1068
  if (!siteConfig.editLink || !sourcePath) {
@@ -871,14 +1070,21 @@ function getEditLinkHref(siteConfig, sourcePath) {
871
1070
  }
872
1071
  return `${siteConfig.editLink.baseUrl}${sourcePath}`;
873
1072
  }
874
- async function resolveTopNav(store, siteConfig) {
1073
+ async function resolveTopNav(store, siteConfig, localeConfig = null) {
1074
+ if (localeConfig !== null && (localeConfig.topNav?.length ?? 0) > 0) {
1075
+ return {
1076
+ items: localeConfig.topNav,
1077
+ autoGenerated: false,
1078
+ };
1079
+ }
875
1080
  if (siteConfig.topNav.length > 0) {
876
1081
  return {
877
1082
  items: siteConfig.topNav,
878
1083
  autoGenerated: false,
879
1084
  };
880
1085
  }
881
- const rootEntries = await store.listDirectory('');
1086
+ const contentRoot = localeConfig?.contentBase ?? '';
1087
+ const rootEntries = await store.listDirectory(contentRoot);
882
1088
  if (rootEntries === null) {
883
1089
  return {
884
1090
  items: [],
@@ -886,16 +1092,22 @@ async function resolveTopNav(store, siteConfig) {
886
1092
  };
887
1093
  }
888
1094
  const directories = rootEntries.filter((entry) => entry.kind === 'directory');
1095
+ const localeDirectoryNames = new Set((siteConfig.locales ?? [])
1096
+ .filter((locale) => locale.contentBase !== '')
1097
+ .map((locale) => locale.contentBase));
889
1098
  const navItems = [];
890
1099
  const orderedNavItems = [];
891
1100
  for (const entry of directories) {
1101
+ if (contentRoot === '' && localeDirectoryNames.has(entry.name)) {
1102
+ continue;
1103
+ }
892
1104
  const resolved = await resolveDirectoryNav(store, entry);
893
1105
  if (resolved.type !== 'page') {
894
1106
  continue;
895
1107
  }
896
1108
  orderedNavItems.push({
897
1109
  label: resolved.title,
898
- href: `/${entry.name}/`,
1110
+ href: `${localeConfig?.pathPrefix ?? ''}/${entry.name}/`,
899
1111
  order: resolved.order,
900
1112
  });
901
1113
  }
@@ -1,3 +1,4 @@
1
+ import type { ResolvedLocaleConfig } from './site-config.js';
1
2
  export type ResolvedRequestKind = 'markdown' | 'html' | 'asset' | 'not-found';
2
3
  export interface ResolvedRequest {
3
4
  kind: ResolvedRequestKind;
@@ -6,3 +7,11 @@ export interface ResolvedRequest {
6
7
  }
7
8
  export declare function resolveRequest(pathname: string): ResolvedRequest;
8
9
  export declare function normalizeRequestPath(pathname: string): string | null;
10
+ /**
11
+ * Attributes a request path to a configured content locale. Locale URL
12
+ * prefixes map 1:1 to top-level `{code}` content directories, so attribution
13
+ * never rewrites content resolution: a path that matches a locale prefix keeps
14
+ * resolving to that locale's directory, and any other path belongs to the
15
+ * default locale (whose content lives at the content root when unprefixed).
16
+ */
17
+ export declare function matchRequestLocale(pathname: string, locales: readonly ResolvedLocaleConfig[] | undefined): ResolvedLocaleConfig | null;
@@ -80,3 +80,29 @@ export function normalizeRequestPath(pathname) {
80
80
  return null;
81
81
  }
82
82
  }
83
+ /**
84
+ * Attributes a request path to a configured content locale. Locale URL
85
+ * prefixes map 1:1 to top-level `{code}` content directories, so attribution
86
+ * never rewrites content resolution: a path that matches a locale prefix keeps
87
+ * resolving to that locale's directory, and any other path belongs to the
88
+ * default locale (whose content lives at the content root when unprefixed).
89
+ */
90
+ export function matchRequestLocale(pathname, locales) {
91
+ if (locales === undefined || locales.length === 0) {
92
+ return null;
93
+ }
94
+ const normalized = normalizeRequestPath(pathname);
95
+ if (normalized === null) {
96
+ return null;
97
+ }
98
+ const prefixed = locales
99
+ .filter((locale) => locale.pathPrefix !== '')
100
+ .sort((left, right) => right.pathPrefix.length - left.pathPrefix.length);
101
+ for (const locale of prefixed) {
102
+ if (normalized === locale.pathPrefix ||
103
+ normalized.startsWith(`${locale.pathPrefix}/`)) {
104
+ return locale;
105
+ }
106
+ }
107
+ return locales.find((locale) => locale.isDefault) ?? null;
108
+ }