mdorigin 0.5.1 → 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.
@@ -98,7 +98,7 @@ export async function handleSiteRequest(store, pathname, options) {
98
98
  if (parsed.meta.draft === true && options.draftMode === 'exclude') {
99
99
  return renderNotFoundForResolvedRequest(store, resolved, options, negotiatedMarkdown, requestLocale);
100
100
  }
101
- const navigation = await resolveTopNav(store, options.siteConfig);
101
+ const navigation = await resolveTopNav(store, options.siteConfig, requestLocale);
102
102
  const renderedBody = isRootHomeRequest(resolved.requestPath) && !options.siteConfig.showHomeIndex
103
103
  ? stripManagedIndexBlock(entry.text)
104
104
  : isRootHomeRequest(resolved.requestPath) && navigation.items.length > 0
@@ -166,8 +166,8 @@ function buildPageRenderModel(options) {
166
166
  sourcePath: options.sourcePath,
167
167
  locale: options.locale,
168
168
  languages: options.languages,
169
- siteTitle: options.siteConfig.siteTitle,
170
- siteDescription: options.siteConfig.siteDescription,
169
+ siteTitle: options.siteTitle ?? options.siteConfig.siteTitle,
170
+ siteDescription: options.siteDescription ?? options.siteConfig.siteDescription,
171
171
  siteUrl: options.siteConfig.siteUrl,
172
172
  favicon: options.siteConfig.favicon,
173
173
  socialImage: options.siteConfig.socialImage,
@@ -182,7 +182,7 @@ function buildPageRenderModel(options) {
182
182
  showSummary: options.siteConfig.showSummary,
183
183
  showDate: options.siteConfig.showDate,
184
184
  topNav: options.topNav,
185
- footerNav: options.siteConfig.footerNav,
185
+ footerNav: options.footerNav ?? options.siteConfig.footerNav,
186
186
  footerText: options.siteConfig.footerText,
187
187
  socialLinks: options.siteConfig.socialLinks,
188
188
  editLink: options.siteConfig.editLink,
@@ -213,6 +213,9 @@ async function renderStructuredPage(options) {
213
213
  renderedBodyHtml: options.renderedParsed.html,
214
214
  parsed: options.parsed,
215
215
  siteConfig: options.siteConfig,
216
+ siteTitle: getEffectiveSiteTitle(options.siteConfig, localeConfig),
217
+ siteDescription: getEffectiveSiteDescription(options.siteConfig, localeConfig),
218
+ footerNav: getEffectiveFooterNav(options.siteConfig, localeConfig),
216
219
  topNav: options.topNav,
217
220
  listingEntries: options.listingEntries,
218
221
  searchEnabled: options.searchEnabled,
@@ -334,8 +337,8 @@ async function renderNotFoundForResolvedRequest(store, resolved, options, negoti
334
337
  return renderHtmlNotFound(store, resolved.requestPath, options, varyOnAccept, requestLocale);
335
338
  }
336
339
  async function renderHtmlNotFound(store, requestPath, options, varyOnAccept, requestLocale) {
337
- const navigation = await resolveTopNav(store, options.siteConfig);
338
340
  const localeConfig = requestLocale;
341
+ const navigation = await resolveTopNav(store, options.siteConfig, localeConfig);
339
342
  const locale = localeConfig?.code ?? options.siteConfig.locale;
340
343
  const messages = getEffectiveLocaleMessages(options.siteConfig, localeConfig);
341
344
  const languages = await buildLanguageOptions(store, {}, localeConfig, options.siteConfig, options.draftMode);
@@ -351,8 +354,8 @@ async function renderHtmlNotFound(store, requestPath, options, varyOnAccept, req
351
354
  'content-type': 'text/html; charset=utf-8',
352
355
  }, varyOnAccept),
353
356
  body: renderDocument({
354
- siteTitle: options.siteConfig.siteTitle,
355
- siteDescription: options.siteConfig.siteDescription,
357
+ siteTitle: getEffectiveSiteTitle(options.siteConfig, localeConfig),
358
+ siteDescription: getEffectiveSiteDescription(options.siteConfig, localeConfig),
356
359
  siteUrl: options.siteConfig.siteUrl,
357
360
  favicon: options.siteConfig.favicon,
358
361
  socialImage: options.siteConfig.socialImage,
@@ -365,7 +368,7 @@ async function renderHtmlNotFound(store, requestPath, options, varyOnAccept, req
365
368
  showSummary: false,
366
369
  showDate: false,
367
370
  topNav: navigation.items,
368
- footerNav: options.siteConfig.footerNav,
371
+ footerNav: getEffectiveFooterNav(options.siteConfig, localeConfig),
369
372
  footerText: options.siteConfig.footerText,
370
373
  socialLinks: options.siteConfig.socialLinks,
371
374
  stylesheetContent: options.siteConfig.stylesheetContent,
@@ -402,6 +405,18 @@ function getEffectiveLocaleMessages(siteConfig, localeConfig) {
402
405
  ...localeConfig.messages,
403
406
  });
404
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
+ }
405
420
  function getFrontmatterLocale(meta) {
406
421
  if (typeof meta.lang !== 'string') {
407
422
  return null;
@@ -552,8 +567,9 @@ async function renderRssFeed(store, options, locale) {
552
567
  const items = await collectRssFeedItems(store, locale?.contentBase ?? '', options, excludedLocaleDirectories);
553
568
  const limitedItems = items.slice(0, options.siteConfig.rss?.maxItems ?? 20);
554
569
  const rssFeedUrl = getRssFeedUrl(options.siteConfig.siteUrl, options.siteConfig, locale);
555
- const title = options.siteConfig.rss?.title ?? options.siteConfig.siteTitle;
556
- const description = options.siteConfig.rss?.description ?? options.siteConfig.siteDescription;
570
+ const title = options.siteConfig.rss?.title ?? getEffectiveSiteTitle(options.siteConfig, locale);
571
+ const description = options.siteConfig.rss?.description ??
572
+ getEffectiveSiteDescription(options.siteConfig, locale);
557
573
  const lastBuildDate = limitedItems[0]?.pubDate.toUTCString();
558
574
  const body = [
559
575
  '<?xml version="1.0" encoding="UTF-8"?>',
@@ -746,8 +762,8 @@ async function renderDirectoryListing(store, requestPath, siteConfig, searchEnab
746
762
  return notFound();
747
763
  }
748
764
  const visibleEntries = entries.filter(isVisibleDirectoryEntry);
749
- const navigation = await resolveTopNav(store, siteConfig);
750
765
  const locale = requestLocale?.code ?? siteConfig.locale;
766
+ const navigation = await resolveTopNav(store, siteConfig, requestLocale);
751
767
  const messages = getEffectiveLocaleMessages(siteConfig, requestLocale);
752
768
  const languages = await buildLanguageOptions(store, { directoryPath }, requestLocale, siteConfig, 'exclude');
753
769
  const listItems = visibleEntries
@@ -765,8 +781,8 @@ async function renderDirectoryListing(store, requestPath, siteConfig, searchEnab
765
781
  'content-type': 'text/html; charset=utf-8',
766
782
  },
767
783
  body: renderDocument({
768
- siteTitle: siteConfig.siteTitle,
769
- siteDescription: siteConfig.siteDescription,
784
+ siteTitle: getEffectiveSiteTitle(siteConfig, requestLocale),
785
+ siteDescription: getEffectiveSiteDescription(siteConfig, requestLocale),
770
786
  locale,
771
787
  messages,
772
788
  languages,
@@ -778,7 +794,7 @@ async function renderDirectoryListing(store, requestPath, siteConfig, searchEnab
778
794
  showSummary: false,
779
795
  showDate: false,
780
796
  topNav: navigation.items,
781
- footerNav: siteConfig.footerNav,
797
+ footerNav: getEffectiveFooterNav(siteConfig, requestLocale),
782
798
  footerText: siteConfig.footerText,
783
799
  socialLinks: siteConfig.socialLinks,
784
800
  stylesheetContent: siteConfig.stylesheetContent,
@@ -830,7 +846,8 @@ async function tryRenderAlternateDirectoryIndex(store, requestPath, options) {
830
846
  if (parsed.meta.draft === true && options.draftMode === 'exclude') {
831
847
  return notFound();
832
848
  }
833
- const navigation = await resolveTopNav(store, options.siteConfig);
849
+ const requestLocale = matchRequestLocale(requestPath, options.siteConfig.locales);
850
+ const navigation = await resolveTopNav(store, options.siteConfig, requestLocale);
834
851
  const renderedBody = isRootHomeRequest(requestPath) && !options.siteConfig.showHomeIndex
835
852
  ? stripManagedIndexBlock(entry.text)
836
853
  : isRootHomeRequest(requestPath) && navigation.items.length > 0
@@ -861,7 +878,7 @@ async function tryRenderAlternateDirectoryIndex(store, requestPath, options) {
861
878
  searchEnabled: options.searchApi !== undefined,
862
879
  plugins,
863
880
  store,
864
- requestLocale: matchRequestLocale(requestPath, options.siteConfig.locales),
881
+ requestLocale,
865
882
  draftMode: options.draftMode,
866
883
  });
867
884
  }
@@ -1053,14 +1070,21 @@ function getEditLinkHref(siteConfig, sourcePath) {
1053
1070
  }
1054
1071
  return `${siteConfig.editLink.baseUrl}${sourcePath}`;
1055
1072
  }
1056
- 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
+ }
1057
1080
  if (siteConfig.topNav.length > 0) {
1058
1081
  return {
1059
1082
  items: siteConfig.topNav,
1060
1083
  autoGenerated: false,
1061
1084
  };
1062
1085
  }
1063
- const rootEntries = await store.listDirectory('');
1086
+ const contentRoot = localeConfig?.contentBase ?? '';
1087
+ const rootEntries = await store.listDirectory(contentRoot);
1064
1088
  if (rootEntries === null) {
1065
1089
  return {
1066
1090
  items: [],
@@ -1074,7 +1098,7 @@ async function resolveTopNav(store, siteConfig) {
1074
1098
  const navItems = [];
1075
1099
  const orderedNavItems = [];
1076
1100
  for (const entry of directories) {
1077
- if (localeDirectoryNames.has(entry.name)) {
1101
+ if (contentRoot === '' && localeDirectoryNames.has(entry.name)) {
1078
1102
  continue;
1079
1103
  }
1080
1104
  const resolved = await resolveDirectoryNav(store, entry);
@@ -1083,7 +1107,7 @@ async function resolveTopNav(store, siteConfig) {
1083
1107
  }
1084
1108
  orderedNavItems.push({
1085
1109
  label: resolved.title,
1086
- href: `/${entry.name}/`,
1110
+ href: `${localeConfig?.pathPrefix ?? ''}/${entry.name}/`,
1087
1111
  order: resolved.order,
1088
1112
  });
1089
1113
  }
@@ -147,6 +147,14 @@ export interface LocaleConfigInput {
147
147
  default?: boolean;
148
148
  /** UI message overrides for this locale; win over global `messages`. */
149
149
  messages?: Partial<SiteMessages>;
150
+ /** Site title override for this locale; wins over the global `siteTitle`. */
151
+ siteTitle?: string;
152
+ /** Site description override for this locale; wins over the global `siteDescription`. */
153
+ siteDescription?: string;
154
+ /** Explicit top navigation for this locale; wins over the global `topNav`. */
155
+ topNav?: SiteNavItem[];
156
+ /** Explicit footer navigation for this locale; wins over the global `footerNav`. */
157
+ footerNav?: SiteNavItem[];
150
158
  }
151
159
  export interface ResolvedLocaleConfig {
152
160
  code: string;
@@ -156,6 +164,14 @@ export interface ResolvedLocaleConfig {
156
164
  /** Content base directory: '' (content root) for an unprefixed default locale, otherwise `{code}`. */
157
165
  contentBase: string;
158
166
  messages: Partial<SiteMessages>;
167
+ /** Site title override; undefined falls back to the global `siteTitle`. */
168
+ siteTitle?: string;
169
+ /** Site description override; undefined falls back to the global `siteDescription`. */
170
+ siteDescription?: string;
171
+ /** Explicit top navigation override; empty array falls back to the global `topNav`. */
172
+ topNav: SiteNavItem[];
173
+ /** Explicit footer navigation override; empty array falls back to the global `footerNav`. */
174
+ footerNav: SiteNavItem[];
159
175
  }
160
176
  export declare function loadSiteConfig(options?: LoadSiteConfigOptions): Promise<ResolvedSiteConfig>;
161
177
  export declare function loadUserSiteConfig(options?: LoadSiteConfigOptions): Promise<LoadedSiteConfig>;
@@ -151,6 +151,10 @@ function resolveLocalesConfig(parsedConfig, configFilePath) {
151
151
  pathPrefix,
152
152
  isDefault,
153
153
  messages,
154
+ siteTitle: normalizeOptionalSiteText(locale.siteTitle),
155
+ siteDescription: normalizeOptionalSiteText(locale.siteDescription),
156
+ topNav: normalizeTopNav(locale.topNav),
157
+ footerNav: normalizeTopNav(locale.footerNav),
154
158
  });
155
159
  }
156
160
  const defaultCount = parsed.filter((locale) => locale.isDefault).length;
@@ -283,6 +287,13 @@ function normalizeTopNav(value) {
283
287
  return [];
284
288
  });
285
289
  }
290
+ function normalizeOptionalSiteText(value) {
291
+ if (typeof value !== 'string') {
292
+ return undefined;
293
+ }
294
+ const trimmed = value.trim();
295
+ return trimmed === '' ? undefined : trimmed;
296
+ }
286
297
  function normalizePositiveInteger(value, fallback) {
287
298
  if (typeof value === 'number' && Number.isInteger(value) && value > 0) {
288
299
  return value;
@@ -60,10 +60,19 @@ export function renderDocument(options) {
60
60
  '</div>',
61
61
  ].join('')
62
62
  : '';
63
- const languagesBlock = options.languages && options.languages.length > 1
64
- ? `<nav class="site-languages" aria-label="${escapeHtml(messages['languages.ariaLabel'])}"><ul>${options.languages
65
- .map((language) => `<li><a href="${escapeHtml(language.href)}" hreflang="${escapeHtml(language.code)}"${language.current ? ' aria-current="page"' : ''}>${escapeHtml(language.label)}</a></li>`)
66
- .join('')}</ul></nav>`
63
+ const currentLanguage = options.languages?.find((language) => language.current) ??
64
+ options.languages?.[0];
65
+ const languagesBlock = options.languages && options.languages.length > 1 && currentLanguage
66
+ ? [
67
+ `<nav class="site-languages" aria-label="${escapeHtml(messages['languages.ariaLabel'])}">`,
68
+ '<details class="site-languages__details" data-site-languages>',
69
+ `<summary class="site-languages__toggle"><span class="site-languages__label">${escapeHtml(currentLanguage.label)}</span><svg class="site-languages__chevron" viewBox="0 0 16 16" width="11" height="11" aria-hidden="true" focusable="false"><path d="M4 6.5 8 10.5 12 6.5" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"></path></svg></summary>`,
70
+ `<ul class="site-languages__panel">${options.languages
71
+ .map((language) => `<li><a href="${escapeHtml(language.href)}" hreflang="${escapeHtml(language.code)}"${language.current ? ' aria-current="page"' : ''}>${escapeHtml(language.label)}</a></li>`)
72
+ .join('')}</ul>`,
73
+ '</details>',
74
+ '</nav>',
75
+ ].join('')
67
76
  : '';
68
77
  const footerNavBlock = options.footerNav && options.footerNav.length > 0
69
78
  ? `<nav class="site-footer__nav"><ul>${options.footerNav
@@ -110,6 +119,7 @@ export function renderDocument(options) {
110
119
  const searchScript = options.searchEnabled
111
120
  ? renderSearchScript(messages, options.searchLocaleFilter)
112
121
  : '';
122
+ const languagesScript = options.headerHtml || !languagesBlock ? '' : renderLanguagesScript();
113
123
  const headerBlock = options.headerHtml ??
114
124
  `<header class="site-header"><div class="site-header__inner"><div class="site-header__brand"><p class="site-header__title"><a href="${brandHref}">${logoBlock}<span>${siteTitle}</span></a></p>${siteDescriptionBlock}</div><div class="site-header__actions">${navBlock}${languagesBlock}${searchToggleBlock}</div></div></header>`;
115
125
  const renderedFooterBlock = options.footerHtml ?? footerBlock;
@@ -136,6 +146,7 @@ export function renderDocument(options) {
136
146
  '</main>',
137
147
  renderedFooterBlock,
138
148
  searchScript,
149
+ languagesScript,
139
150
  '</body>',
140
151
  '</html>',
141
152
  ].join('');
@@ -294,6 +305,35 @@ function renderListingLoadMoreScript(messages) {
294
305
  })();
295
306
  </script>`;
296
307
  }
308
+ function renderLanguagesScript() {
309
+ return `<script>
310
+ (function () {
311
+ const menus = Array.from(document.querySelectorAll("details[data-site-languages]"));
312
+ if (menus.length === 0) return;
313
+ document.addEventListener("click", (event) => {
314
+ for (const menu of menus) {
315
+ if (menu.open && !menu.contains(event.target)) menu.open = false;
316
+ }
317
+ });
318
+ document.addEventListener("keydown", (event) => {
319
+ if (event.key !== "Escape") return;
320
+ for (const menu of menus) {
321
+ if (!menu.open) continue;
322
+ menu.open = false;
323
+ menu.querySelector("summary")?.focus();
324
+ }
325
+ });
326
+ for (const menu of menus) {
327
+ menu.addEventListener("toggle", () => {
328
+ if (!menu.open) return;
329
+ for (const other of menus) {
330
+ if (other !== menu) other.open = false;
331
+ }
332
+ });
333
+ }
334
+ })();
335
+ </script>`;
336
+ }
297
337
  function renderSearchScript(messages, localeFilter) {
298
338
  return [
299
339
  '<script>',
@@ -112,6 +112,10 @@ function buildSharedSearchStyles() {
112
112
  flex-direction: column;
113
113
  align-items: stretch;
114
114
  }
115
+ .site-languages__panel {
116
+ left: 0;
117
+ right: auto;
118
+ }
115
119
  .site-search__panel {
116
120
  left: 0;
117
121
  right: auto;
@@ -219,39 +223,76 @@ a:hover { color: var(--link-hover); text-decoration: underline; }
219
223
  white-space: nowrap;
220
224
  }
221
225
  .site-nav a:hover { color: var(--link-hover); }
222
- .site-languages ul {
223
- list-style: none;
224
- display: flex;
225
- flex-wrap: wrap;
226
- gap: 0.6rem;
227
- margin: 0;
228
- padding: 0;
229
- align-items: center;
226
+ main {
227
+ max-width: calc(var(--max) + 4rem);
228
+ margin: 0 auto;
229
+ padding: 2rem;
230
230
  }
231
- .site-languages li {
231
+ .site-languages {
232
+ position: relative;
232
233
  display: flex;
233
- align-items: center;
234
+ align-items: flex-end;
234
235
  }
235
- .site-languages a {
236
+ .site-languages__toggle {
237
+ list-style: none;
238
+ appearance: none;
239
+ display: inline-flex;
240
+ align-items: center;
241
+ gap: 0.35rem;
242
+ min-height: 2.25rem;
243
+ padding: 0.45rem 0.82rem;
244
+ border: 1px solid var(--border);
245
+ border-radius: 999px;
246
+ background: color-mix(in srgb, var(--surface) 92%, transparent);
236
247
  color: var(--muted);
248
+ font: inherit;
237
249
  font-size: 0.85rem;
238
- display: inline-flex;
250
+ cursor: pointer;
251
+ white-space: nowrap;
252
+ }
253
+ .site-languages__toggle::-webkit-details-marker { display: none; }
254
+ .site-languages__toggle:hover,
255
+ .site-languages__details[open] > .site-languages__toggle { color: var(--text); }
256
+ .site-languages__chevron {
257
+ flex: none;
258
+ transition: transform 0.15s ease;
259
+ }
260
+ .site-languages__details[open] > .site-languages__toggle .site-languages__chevron {
261
+ transform: rotate(180deg);
262
+ }
263
+ .site-languages__panel {
264
+ position: absolute;
265
+ top: calc(100% + 0.7rem);
266
+ right: 0;
267
+ list-style: none;
268
+ margin: 0;
269
+ padding: 0.4rem;
270
+ min-width: 9rem;
271
+ border: 1px solid var(--border);
272
+ border-radius: 14px;
273
+ background: color-mix(in srgb, var(--surface) 95%, white 5%);
274
+ box-shadow: 0 18px 40px rgba(24, 18, 11, 0.14);
275
+ z-index: 2;
276
+ }
277
+ .site-languages__panel li { display: flex; }
278
+ .site-languages__panel a {
279
+ flex: 1;
280
+ display: flex;
239
281
  align-items: center;
240
282
  min-height: 2.25rem;
241
- padding: 0 0.05rem;
283
+ padding: 0 0.7rem;
284
+ border-radius: 9px;
285
+ color: var(--muted);
286
+ font-size: 0.88rem;
242
287
  white-space: nowrap;
243
288
  }
244
- .site-languages a:hover { color: var(--link-hover); }
245
- .site-languages a[aria-current='page'] {
246
- color: inherit;
247
- font-weight: 700;
248
- text-decoration: underline;
249
- text-underline-offset: 0.25em;
289
+ .site-languages__panel a:hover {
290
+ color: var(--text);
291
+ background: color-mix(in srgb, var(--border) 26%, transparent);
250
292
  }
251
- main {
252
- max-width: calc(var(--max) + 4rem);
253
- margin: 0 auto;
254
- padding: 2rem;
293
+ .site-languages__panel a[aria-current='page'] {
294
+ color: var(--text);
295
+ font-weight: 700;
255
296
  }
256
297
  .site-footer {
257
298
  max-width: calc(var(--max) + 4rem);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mdorigin",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "Markdown-first publishing for humans and agents.",
6
6
  "repository": {