@lupinum/ginko-content 0.1.4 → 0.1.5
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/compatibility.json +1 -1
- package/dist/core/content/graph.d.ts +1 -1
- package/dist/core/references/resolve.d.ts +19 -0
- package/dist/core/references/resolve.js +72 -20
- package/dist/module.d.mts +26 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +25 -2
- package/dist/runtime/app/components/internal/ContentRendererMarkdown.vue +17 -5
- package/dist/runtime/app/composables/content-i18n.js +1 -1
- package/dist/runtime/virtual.d.ts +1 -0
- package/dist/storage/references.js +20 -9
- package/dist/types/module.d.ts +24 -0
- package/dist/types.d.mts +1 -1
- package/dist/web-types.json +1 -1
- package/package.json +1 -1
package/compatibility.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* - **`byRoute`**: route path (user-visible URL) → content id. Used by the
|
|
17
17
|
* page resolver when the request arrives as a localized URL.
|
|
18
18
|
* - **`byRef`**: normalized ref string → canonical key. This is how
|
|
19
|
-
* `[
|
|
19
|
+
* markdown links such as `[Ada]($authors.ada)` find their target without a scan.
|
|
20
20
|
* - **`referenceTargets`**: the `buildReferenceTargets` map — every shape
|
|
21
21
|
* the user might plausibly write to point at a document (canonical
|
|
22
22
|
* name, locale-prefixed path, short slug) pre-resolved to a canonical
|
|
@@ -28,4 +28,23 @@ export declare const parseRefLink: (value: string) => {
|
|
|
28
28
|
} | null;
|
|
29
29
|
export declare const collectMarkdownRefLinks: (node: unknown) => string[];
|
|
30
30
|
export declare const rewriteMarkdownRefLinks: <T>(node: T, resolvedRefs?: Record<string, string>) => T;
|
|
31
|
+
export interface MarkdownQuickLinkTarget {
|
|
32
|
+
route: string;
|
|
33
|
+
params?: Record<string, string | number>;
|
|
34
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
35
|
+
}
|
|
36
|
+
export type MarkdownQuickLinks = Record<string, Record<string, MarkdownQuickLinkTarget>>;
|
|
37
|
+
export type ResolveQuickLinkRoute = (route: {
|
|
38
|
+
name: string;
|
|
39
|
+
hash?: string;
|
|
40
|
+
params?: Record<string, string | number>;
|
|
41
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
42
|
+
}) => string;
|
|
43
|
+
export declare const resolveConfiguredQuickLink: (href: string, links: MarkdownQuickLinks | undefined, resolveRoute: ResolveQuickLinkRoute) => string | undefined;
|
|
44
|
+
export declare const resolveConfiguredQuickLinks: (hrefs: string[], links: MarkdownQuickLinks | undefined, resolveRoute: ResolveQuickLinkRoute) => {
|
|
45
|
+
[k: string]: string;
|
|
46
|
+
};
|
|
47
|
+
export declare const resolveMarkdownRenderRefs: (node: unknown, resolvedRefs: Record<string, string> | undefined, links: MarkdownQuickLinks | undefined, resolveRoute: ResolveQuickLinkRoute) => {
|
|
48
|
+
[x: string]: string;
|
|
49
|
+
};
|
|
31
50
|
export declare const buildReferenceTargets: (contents: ParsedContent[], locales?: string[]) => Map<string, string>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isMarkdownRoot, mapMarkdownNode } from "../markdown/tree.js";
|
|
2
2
|
export const CONTENT_REF_LINK_PREFIX = "$";
|
|
3
|
+
const MARKDOWN_LINK_PROP_KEYS = ["href", "to"];
|
|
3
4
|
export const normalizeReferenceValue = (value) => String(value).replace(/^\/+|\/+$/g, "");
|
|
4
5
|
export const parseRefLink = (value) => {
|
|
5
6
|
if (typeof value !== "string" || !value.startsWith(CONTENT_REF_LINK_PREFIX)) {
|
|
@@ -17,6 +18,17 @@ export const parseRefLink = (value) => {
|
|
|
17
18
|
};
|
|
18
19
|
export const collectMarkdownRefLinks = (node) => {
|
|
19
20
|
const refs = /* @__PURE__ */ new Set();
|
|
21
|
+
const collectProps = (props) => {
|
|
22
|
+
if (!props || typeof props !== "object") {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const key of MARKDOWN_LINK_PROP_KEYS) {
|
|
26
|
+
const value = props[key];
|
|
27
|
+
if (typeof value === "string" && parseRefLink(value)) {
|
|
28
|
+
refs.add(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
20
32
|
const visit = (current) => {
|
|
21
33
|
if (!current || typeof current !== "object") {
|
|
22
34
|
return;
|
|
@@ -27,10 +39,7 @@ export const collectMarkdownRefLinks = (node) => {
|
|
|
27
39
|
}
|
|
28
40
|
if (current.type === "element") {
|
|
29
41
|
const markdownNode = current;
|
|
30
|
-
|
|
31
|
-
if (href2 && parseRefLink(href2)) {
|
|
32
|
-
refs.add(href2);
|
|
33
|
-
}
|
|
42
|
+
collectProps(markdownNode.props);
|
|
34
43
|
markdownNode.children?.forEach(visit);
|
|
35
44
|
return;
|
|
36
45
|
}
|
|
@@ -38,16 +47,27 @@ export const collectMarkdownRefLinks = (node) => {
|
|
|
38
47
|
current.forEach(visit);
|
|
39
48
|
return;
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
if (href && parseRefLink(href)) {
|
|
43
|
-
refs.add(href);
|
|
44
|
-
}
|
|
50
|
+
collectProps(current.props);
|
|
45
51
|
visit(current.children);
|
|
46
52
|
};
|
|
47
53
|
visit(node);
|
|
48
54
|
return Array.from(refs);
|
|
49
55
|
};
|
|
50
56
|
export const rewriteMarkdownRefLinks = (node, resolvedRefs = {}) => {
|
|
57
|
+
const rewriteProps = (props) => {
|
|
58
|
+
if (!props || typeof props !== "object") {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
let next;
|
|
62
|
+
for (const key of MARKDOWN_LINK_PROP_KEYS) {
|
|
63
|
+
const value = props[key];
|
|
64
|
+
if (typeof value === "string" && resolvedRefs[value]) {
|
|
65
|
+
next ||= { ...props };
|
|
66
|
+
next[key] = resolvedRefs[value];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return next || props;
|
|
70
|
+
};
|
|
51
71
|
const visit = (current) => {
|
|
52
72
|
if (!current || typeof current !== "object") {
|
|
53
73
|
return current;
|
|
@@ -60,16 +80,13 @@ export const rewriteMarkdownRefLinks = (node, resolvedRefs = {}) => {
|
|
|
60
80
|
}
|
|
61
81
|
if (current.type === "element") {
|
|
62
82
|
return mapMarkdownNode(current, (markdownNode) => {
|
|
63
|
-
const
|
|
64
|
-
if (
|
|
83
|
+
const props2 = rewriteProps(markdownNode.props);
|
|
84
|
+
if (props2 === markdownNode.props) {
|
|
65
85
|
return markdownNode;
|
|
66
86
|
}
|
|
67
87
|
return {
|
|
68
88
|
...markdownNode,
|
|
69
|
-
props:
|
|
70
|
-
...markdownNode.props,
|
|
71
|
-
href: resolvedRefs[href2]
|
|
72
|
-
}
|
|
89
|
+
props: props2
|
|
73
90
|
};
|
|
74
91
|
});
|
|
75
92
|
}
|
|
@@ -77,12 +94,9 @@ export const rewriteMarkdownRefLinks = (node, resolvedRefs = {}) => {
|
|
|
77
94
|
return current.map((item) => visit(item));
|
|
78
95
|
}
|
|
79
96
|
const next = { ...current };
|
|
80
|
-
const
|
|
81
|
-
if (
|
|
82
|
-
next.props =
|
|
83
|
-
...next.props,
|
|
84
|
-
href: resolvedRefs[href]
|
|
85
|
-
};
|
|
97
|
+
const props = rewriteProps(next.props);
|
|
98
|
+
if (props !== next.props) {
|
|
99
|
+
next.props = props;
|
|
86
100
|
}
|
|
87
101
|
if (Array.isArray(next.children)) {
|
|
88
102
|
next.children = next.children.map((child) => visit(child));
|
|
@@ -91,6 +105,44 @@ export const rewriteMarkdownRefLinks = (node, resolvedRefs = {}) => {
|
|
|
91
105
|
};
|
|
92
106
|
return visit(node);
|
|
93
107
|
};
|
|
108
|
+
export const resolveConfiguredQuickLink = (href, links, resolveRoute) => {
|
|
109
|
+
const parsed = parseRefLink(href);
|
|
110
|
+
if (!parsed || !links) {
|
|
111
|
+
return void 0;
|
|
112
|
+
}
|
|
113
|
+
const separator = parsed.ref.indexOf(".");
|
|
114
|
+
if (separator <= 0 || separator === parsed.ref.length - 1) {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
const namespace = parsed.ref.slice(0, separator);
|
|
118
|
+
const key = parsed.ref.slice(separator + 1);
|
|
119
|
+
const target = links[namespace]?.[key];
|
|
120
|
+
if (!target?.route) {
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
return resolveRoute({
|
|
124
|
+
name: target.route,
|
|
125
|
+
...target.params ? { params: target.params } : {},
|
|
126
|
+
...target.query ? { query: target.query } : {},
|
|
127
|
+
...parsed.hash ? { hash: parsed.hash } : {}
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
export const resolveConfiguredQuickLinks = (hrefs, links, resolveRoute) => {
|
|
131
|
+
return Object.fromEntries(hrefs.flatMap((href) => {
|
|
132
|
+
const resolved = resolveConfiguredQuickLink(href, links, resolveRoute);
|
|
133
|
+
return resolved ? [[href, resolved]] : [];
|
|
134
|
+
}));
|
|
135
|
+
};
|
|
136
|
+
export const resolveMarkdownRenderRefs = (node, resolvedRefs, links, resolveRoute) => {
|
|
137
|
+
const quickRefs = resolveConfiguredQuickLinks(collectMarkdownRefLinks(node), links, resolveRoute);
|
|
138
|
+
const concreteContentRefs = Object.fromEntries(
|
|
139
|
+
Object.entries(resolvedRefs || {}).filter(([href, value]) => value && value !== href)
|
|
140
|
+
);
|
|
141
|
+
return {
|
|
142
|
+
...quickRefs,
|
|
143
|
+
...concreteContentRefs
|
|
144
|
+
};
|
|
145
|
+
};
|
|
94
146
|
export const buildReferenceTargets = (contents, locales = []) => {
|
|
95
147
|
const targets = /* @__PURE__ */ new Map();
|
|
96
148
|
for (const document of contents) {
|
package/dist/module.d.mts
CHANGED
|
@@ -1405,6 +1405,21 @@ interface ContentRevalidateOptions {
|
|
|
1405
1405
|
*/
|
|
1406
1406
|
allowUnsigned?: boolean;
|
|
1407
1407
|
}
|
|
1408
|
+
interface ContentLinkRouteTarget {
|
|
1409
|
+
/**
|
|
1410
|
+
* Nuxt route name passed to Nuxt I18n `localePath()`.
|
|
1411
|
+
*/
|
|
1412
|
+
route: string;
|
|
1413
|
+
/**
|
|
1414
|
+
* Static route params forwarded to Nuxt I18n `localePath()`.
|
|
1415
|
+
*/
|
|
1416
|
+
params?: Record<string, string | number>;
|
|
1417
|
+
/**
|
|
1418
|
+
* Static query params forwarded to Nuxt I18n `localePath()`.
|
|
1419
|
+
*/
|
|
1420
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
1421
|
+
}
|
|
1422
|
+
type ContentLinksOptions = Record<string, Record<string, ContentLinkRouteTarget>>;
|
|
1408
1423
|
interface ContentAgentRouteOptions {
|
|
1409
1424
|
routes?: boolean;
|
|
1410
1425
|
linkHeaders?: boolean;
|
|
@@ -1454,6 +1469,15 @@ interface ModuleOptions {
|
|
|
1454
1469
|
* `x-ginko-revalidate-token` or `authorization: Bearer <token>`.
|
|
1455
1470
|
*/
|
|
1456
1471
|
revalidate?: false | ContentRevalidateOptions;
|
|
1472
|
+
/**
|
|
1473
|
+
* Writer-facing markdown quick links. Values point at Nuxt route names;
|
|
1474
|
+
* localized paths stay owned by Nuxt I18n.
|
|
1475
|
+
*
|
|
1476
|
+
* @example
|
|
1477
|
+
* content.links.main.pricing = { route: 'pricing' }
|
|
1478
|
+
* markdown: [Pricing]($main.pricing)
|
|
1479
|
+
*/
|
|
1480
|
+
links?: ContentLinksOptions;
|
|
1457
1481
|
/**
|
|
1458
1482
|
* First-class agent markdown and LLM route features.
|
|
1459
1483
|
*/
|
|
@@ -1673,6 +1697,7 @@ interface ModulePublicRuntimeConfig {
|
|
|
1673
1697
|
locales: ContentContext$1['locales'];
|
|
1674
1698
|
provider: ContentContext$1['provider'];
|
|
1675
1699
|
providers: ContentContext$1['providers'];
|
|
1700
|
+
links: ContentContext$1['links'];
|
|
1676
1701
|
collections: Record<string, {
|
|
1677
1702
|
source: ContentCollectionConfig$1['source'];
|
|
1678
1703
|
exclude?: ContentCollectionConfig$1['exclude'];
|
|
@@ -1726,4 +1751,4 @@ interface ModuleHooks {
|
|
|
1726
1751
|
}
|
|
1727
1752
|
|
|
1728
1753
|
export { _default as default, normalizeContentConfigCollectionNames };
|
|
1729
|
-
export type { AgentMetadataField, AgentMetadataFieldList, BacklinkFields, BacklinkSource, BacklinksOptions, BacklinksResult, CollectionQueryBuilder, CollectionQueryField, CollectionQueryFieldValue, CollectionQueryKey, CollectionQueryOperator, CollectionQueryValue, CollectionSchema, ContentAgentAppPageConfig, ContentAgentAppPageContext, ContentAgentCollectionConfig, ContentAgentConfig, ContentAgentLocalizedValue, ContentAgentMarkdownMetadataConfig, ContentAgentMarkdownOptions, ContentAgentMarkdownPolicyConfig, ContentAgentRouteOptions, ContentAgentSectionConfig, ContentAgentSiteConfig, ContentCacheArtifact, ContentCmsCollectionConfig, ContentCmsFieldConfig, ContentCmsFieldType, ContentCmsRelationConfig, ContentCollectionConfig, ContentCollectionHandle, ContentCollectionI18nConfig, ContentCollectionI18nMap, ContentCollectionItem, ContentCollectionItemSurroundingsOptions, ContentCollectionKind, ContentCollectionMap, ContentCollectionName, ContentCollectionNavigationOptions, ContentCollectionPageOptions, ContentCollectionRouteConfig, ContentCollectionRouteMetaOptions, ContentCollectionSearchSectionsOptions, ContentCollectionSource, ContentCollectionSourceObject, ContentCollectionStringName, ContentCollectionTarget, ContentConfig, ContentContext, ContentI18nOptions, ContentLocaleEntry, ContentLocaleRoute, ContentManifest, ContentMiniSearchOptions, ContentNavigationItem, ContentPageResult, ContentPreviewOptions, ContentProviderName, ContentProviderSearchRequest, ContentQueryBuilder, ContentQueryBuilderParams, ContentQueryBuilderWhere, ContentQueryFetcher, ContentQueryRequest, ContentQuerySortFields, ContentQuerySortOptions, ContentQuerySortParams, ContentReferenceSchema, ContentResolvedMeta, ContentRevalidateOptions, ContentRouteMeta, ContentSearchEngine, ContentSearchIndexRecord, ContentSearchOptions, ContentSearchPublicRuntimeConfig, ContentSearchResult, ContentSearchSection, ContentSelector, ContentSeoImage, ContentSeoMeta, ContentSitemapAlternative, ContentSitemapAssertOptions, ContentSitemapAssertSitemapOptions, ContentSitemapEntry, ContentSitemapImage, ContentSitemapOptions, ContentTransformer, ContentTreeItem, ContentVariant, DefineCollectionObject, DefineCollectionOptions, DocumentFromHandle, LocaleFallback, LocalePathEntry, LocalizedContentDocument, LocalizedDoc, ManifestVariant, ManyOptions, MarkdownNode, MarkdownOptions, MarkdownParsedContent, MarkdownPluginDescriptor, MarkdownPluginOptions, MarkdownRoot, ModuleHooks, ModuleOptions, MountOptions, NavItem, NeighborsOptions, NeighborsResult, OneOptions, PaginationOptions, PaginationResult, ParseContentOptions, ParsedContent, ParsedContentInternalMeta, ParsedContentMeta, PopulateFromOptions, PopulateSpec, PopulatedDocument, QueryGroupBuilder, QueryGroupFunction, QueryMatchOperator, QueryOperators, QueryOrderDirection, QueryOrderOptions, QueryWhere, ResolutionEnvelope, ResolveContentReferenceOptions, ResolveOneOptions, ResolveOneResult, ResolvedContentContext, ResolvedContentI18nOptions, ResolvedMarkdownPlugin, ResolvedVariant, SortDirection, SortSpec, StrictParsedContent, StrictParsedContentMeta, Toc, TocLink, TransformContentOptions, TransformContentSource, TreeOptions, VariantsOptions };
|
|
1754
|
+
export type { AgentMetadataField, AgentMetadataFieldList, BacklinkFields, BacklinkSource, BacklinksOptions, BacklinksResult, CollectionQueryBuilder, CollectionQueryField, CollectionQueryFieldValue, CollectionQueryKey, CollectionQueryOperator, CollectionQueryValue, CollectionSchema, ContentAgentAppPageConfig, ContentAgentAppPageContext, ContentAgentCollectionConfig, ContentAgentConfig, ContentAgentLocalizedValue, ContentAgentMarkdownMetadataConfig, ContentAgentMarkdownOptions, ContentAgentMarkdownPolicyConfig, ContentAgentRouteOptions, ContentAgentSectionConfig, ContentAgentSiteConfig, ContentCacheArtifact, ContentCmsCollectionConfig, ContentCmsFieldConfig, ContentCmsFieldType, ContentCmsRelationConfig, ContentCollectionConfig, ContentCollectionHandle, ContentCollectionI18nConfig, ContentCollectionI18nMap, ContentCollectionItem, ContentCollectionItemSurroundingsOptions, ContentCollectionKind, ContentCollectionMap, ContentCollectionName, ContentCollectionNavigationOptions, ContentCollectionPageOptions, ContentCollectionRouteConfig, ContentCollectionRouteMetaOptions, ContentCollectionSearchSectionsOptions, ContentCollectionSource, ContentCollectionSourceObject, ContentCollectionStringName, ContentCollectionTarget, ContentConfig, ContentContext, ContentI18nOptions, ContentLinkRouteTarget, ContentLinksOptions, ContentLocaleEntry, ContentLocaleRoute, ContentManifest, ContentMiniSearchOptions, ContentNavigationItem, ContentPageResult, ContentPreviewOptions, ContentProviderName, ContentProviderSearchRequest, ContentQueryBuilder, ContentQueryBuilderParams, ContentQueryBuilderWhere, ContentQueryFetcher, ContentQueryRequest, ContentQuerySortFields, ContentQuerySortOptions, ContentQuerySortParams, ContentReferenceSchema, ContentResolvedMeta, ContentRevalidateOptions, ContentRouteMeta, ContentSearchEngine, ContentSearchIndexRecord, ContentSearchOptions, ContentSearchPublicRuntimeConfig, ContentSearchResult, ContentSearchSection, ContentSelector, ContentSeoImage, ContentSeoMeta, ContentSitemapAlternative, ContentSitemapAssertOptions, ContentSitemapAssertSitemapOptions, ContentSitemapEntry, ContentSitemapImage, ContentSitemapOptions, ContentTransformer, ContentTreeItem, ContentVariant, DefineCollectionObject, DefineCollectionOptions, DocumentFromHandle, LocaleFallback, LocalePathEntry, LocalizedContentDocument, LocalizedDoc, ManifestVariant, ManyOptions, MarkdownNode, MarkdownOptions, MarkdownParsedContent, MarkdownPluginDescriptor, MarkdownPluginOptions, MarkdownRoot, ModuleHooks, ModuleOptions, MountOptions, NavItem, NeighborsOptions, NeighborsResult, OneOptions, PaginationOptions, PaginationResult, ParseContentOptions, ParsedContent, ParsedContentInternalMeta, ParsedContentMeta, PopulateFromOptions, PopulateSpec, PopulatedDocument, QueryGroupBuilder, QueryGroupFunction, QueryMatchOperator, QueryOperators, QueryOrderDirection, QueryOrderOptions, QueryWhere, ResolutionEnvelope, ResolveContentReferenceOptions, ResolveOneOptions, ResolveOneResult, ResolvedContentContext, ResolvedContentI18nOptions, ResolvedMarkdownPlugin, ResolvedVariant, SortDirection, SortSpec, StrictParsedContent, StrictParsedContentMeta, Toc, TocLink, TransformContentOptions, TransformContentSource, TreeOptions, VariantsOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -30,7 +30,7 @@ export { agentMetadataFields, defineAgentAppPage, defineAgentMarkdownPolicy, def
|
|
|
30
30
|
import { collectTopLevelReferenceFieldsByTarget } from '../dist/core/references/schema';
|
|
31
31
|
|
|
32
32
|
const name = "@lupinum/ginko-content";
|
|
33
|
-
const version = "0.1.
|
|
33
|
+
const version = "0.1.5";
|
|
34
34
|
|
|
35
35
|
const CONFIG_FILES = [
|
|
36
36
|
"content.config.ts",
|
|
@@ -302,8 +302,9 @@ const registerContentI18nTemplate = (addTemplateImpl, hasNuxtI18nModule) => {
|
|
|
302
302
|
filename: "content-i18n.mjs",
|
|
303
303
|
write: true,
|
|
304
304
|
getContents: () => hasNuxtI18nModule ? [
|
|
305
|
-
"export { useRouteBaseName, useSetI18nParams, useSwitchLocalePath } from '#i18n'"
|
|
305
|
+
"export { useLocalePath, useRouteBaseName, useSetI18nParams, useSwitchLocalePath } from '#i18n'"
|
|
306
306
|
].join("\n") : [
|
|
307
|
+
"import { useRouter } from '#imports'",
|
|
307
308
|
"const routeNameLocaleRE = /___([^_]+)$/",
|
|
308
309
|
"const resolveName = (value) => {",
|
|
309
310
|
" if (typeof value === 'string') {",
|
|
@@ -314,6 +315,24 @@ const registerContentI18nTemplate = (addTemplateImpl, hasNuxtI18nModule) => {
|
|
|
314
315
|
" }",
|
|
315
316
|
" return undefined",
|
|
316
317
|
"}",
|
|
318
|
+
"const normalizeRoutePath = (value) => value.startsWith('/') ? value : `/${value}`",
|
|
319
|
+
"const definedRecord = value => value && typeof value === 'object'",
|
|
320
|
+
" ? Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined))",
|
|
321
|
+
" : undefined",
|
|
322
|
+
"export const useLocalePath = () => {",
|
|
323
|
+
" const router = useRouter()",
|
|
324
|
+
" return (value) => {",
|
|
325
|
+
" if (typeof value === 'string') return normalizeRoutePath(value)",
|
|
326
|
+
" const name = resolveName(value)",
|
|
327
|
+
" if (!name) return ''",
|
|
328
|
+
" return router.resolve({",
|
|
329
|
+
" name,",
|
|
330
|
+
" ...(definedRecord(value.params) ? { params: definedRecord(value.params) } : {}),",
|
|
331
|
+
" ...(definedRecord(value.query) ? { query: definedRecord(value.query) } : {}),",
|
|
332
|
+
" ...(typeof value.hash === 'string' ? { hash: value.hash } : {})",
|
|
333
|
+
" }).href",
|
|
334
|
+
" }",
|
|
335
|
+
"}",
|
|
317
336
|
"export const useRouteBaseName = () => (value) => {",
|
|
318
337
|
" const name = resolveName(value)",
|
|
319
338
|
" return typeof name === 'string' ? name.replace(routeNameLocaleRE, '') : undefined",
|
|
@@ -326,6 +345,7 @@ const registerContentI18nTemplate = (addTemplateImpl, hasNuxtI18nModule) => {
|
|
|
326
345
|
filename: "content-i18n.d.mts",
|
|
327
346
|
write: true,
|
|
328
347
|
getContents: () => [
|
|
348
|
+
"export function useLocalePath(): (route: string | { name?: string, hash?: string, params?: Record<string, unknown>, query?: Record<string, unknown> }, locale?: string) => string",
|
|
329
349
|
"export function useRouteBaseName(): (route: { name?: unknown } | unknown) => string | undefined",
|
|
330
350
|
"export function useSetI18nParams(): (params: Record<string, unknown>) => void",
|
|
331
351
|
"export function useSwitchLocalePath(): (locale: string) => string"
|
|
@@ -335,6 +355,7 @@ const registerContentI18nTemplate = (addTemplateImpl, hasNuxtI18nModule) => {
|
|
|
335
355
|
filename: "types/content-i18n.d.ts",
|
|
336
356
|
getContents: () => [
|
|
337
357
|
"declare module '#build/content-i18n.mjs' {",
|
|
358
|
+
" export function useLocalePath(): (route: string | { name?: string, hash?: string, params?: Record<string, unknown>, query?: Record<string, unknown> }, locale?: string) => string",
|
|
338
359
|
" export function useRouteBaseName(): (route: { name?: unknown } | unknown) => string | undefined",
|
|
339
360
|
" export function useSetI18nParams(): (params: Record<string, unknown>) => void",
|
|
340
361
|
" export function useSwitchLocalePath(): (locale: string) => string",
|
|
@@ -1557,6 +1578,7 @@ const contentModuleDefaults = {
|
|
|
1557
1578
|
watch: true,
|
|
1558
1579
|
sources: {},
|
|
1559
1580
|
ignores: [],
|
|
1581
|
+
links: {},
|
|
1560
1582
|
collections: {},
|
|
1561
1583
|
markdown: {
|
|
1562
1584
|
plugins: [],
|
|
@@ -1661,6 +1683,7 @@ const applyContentRuntimeConfig = (nuxt, options, contentContext, runtimeCollect
|
|
|
1661
1683
|
translatedSlugs: contentContext.translatedSlugs ?? false,
|
|
1662
1684
|
strictTranslatedSlugs: contentContext.strictTranslatedSlugs ?? false,
|
|
1663
1685
|
collections: runtimeCollections,
|
|
1686
|
+
links: contentContext.links || {},
|
|
1664
1687
|
integrity: buildIntegrity,
|
|
1665
1688
|
experimental: {
|
|
1666
1689
|
stripQueryParameters: options.experimental.stripQueryParameters
|
|
@@ -4,7 +4,8 @@ import { useRuntimeConfig } from "#imports";
|
|
|
4
4
|
import { useContentPreview } from "../../composables/preview";
|
|
5
5
|
import { useUnwrap } from "../../composables/useUnwrap";
|
|
6
6
|
import MarkdownRenderer from "./MarkdownRenderer.js";
|
|
7
|
-
import {
|
|
7
|
+
import { useLocalePath } from "../../composables/content-i18n";
|
|
8
|
+
import { resolveMarkdownRenderRefs, rewriteMarkdownRefLinks } from "../../../../core/references/resolve";
|
|
8
9
|
import { loadContentComponentEntries } from "../../../../integrations/vue/content-components";
|
|
9
10
|
import { resolveMarkdownRendererComponents } from "../../../markdown/plugins";
|
|
10
11
|
import { isMarkdownRoot } from "../../../../core/markdown/tree";
|
|
@@ -39,14 +40,19 @@ const props = defineProps({
|
|
|
39
40
|
}
|
|
40
41
|
});
|
|
41
42
|
const debug = import.meta.dev || useContentPreview().isEnabled();
|
|
42
|
-
const runtimeContent = useRuntimeConfig().public
|
|
43
|
+
const runtimeContent = useRuntimeConfig().public?.content || {};
|
|
43
44
|
const attrs = useAttrs();
|
|
44
45
|
const { unwrap: unwrapRoot } = useUnwrap();
|
|
46
|
+
const localePath = useLocalePath();
|
|
45
47
|
const locale = computed(() => props.value.locale || props.value._resolvedLocale || props.value._locale);
|
|
48
|
+
const linkLocale = computed(() => props.value._requestedLocale || locale.value);
|
|
46
49
|
const defaultLocale = computed(() => props.value.defaultLocale || runtimeContent.defaultLocale);
|
|
47
50
|
const locales = computed(() => {
|
|
48
51
|
const variantLocales = Array.isArray(props.value.variants) ? props.value.variants.map((variant) => variant.locale).filter((locale2) => Boolean(locale2)) : [];
|
|
49
|
-
return
|
|
52
|
+
return Array.from(/* @__PURE__ */ new Set([
|
|
53
|
+
...runtimeContent.locales || [],
|
|
54
|
+
...variantLocales
|
|
55
|
+
]));
|
|
50
56
|
});
|
|
51
57
|
const body = computed(() => {
|
|
52
58
|
let body2 = props.value.body || props.value;
|
|
@@ -56,7 +62,13 @@ const body = computed(() => {
|
|
|
56
62
|
if (!isMarkdownRoot(body2)) {
|
|
57
63
|
return null;
|
|
58
64
|
}
|
|
59
|
-
|
|
65
|
+
const resolvedRefs = resolveMarkdownRenderRefs(
|
|
66
|
+
body2,
|
|
67
|
+
props.value._resolvedRefs,
|
|
68
|
+
runtimeContent.links,
|
|
69
|
+
(route) => localePath(route, linkLocale.value)
|
|
70
|
+
);
|
|
71
|
+
return Object.keys(resolvedRefs).length ? rewriteMarkdownRefLinks(body2, resolvedRefs) : body2;
|
|
60
72
|
});
|
|
61
73
|
const renderedBody = computed(() => {
|
|
62
74
|
if (!body.value) {
|
|
@@ -70,7 +82,7 @@ const resolvedComponents = computed(() => {
|
|
|
70
82
|
}
|
|
71
83
|
return {
|
|
72
84
|
...Object.fromEntries(loadContentComponentEntries(renderedBody.value, runtimeContent.markdown?.tags || {})),
|
|
73
|
-
...resolveMarkdownRendererComponents(runtimeContent.markdown
|
|
85
|
+
...resolveMarkdownRendererComponents(runtimeContent.markdown?.plugins || []),
|
|
74
86
|
...props.components
|
|
75
87
|
};
|
|
76
88
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useRouteBaseName, useSetI18nParams, useSwitchLocalePath } from "#build/content-i18n.mjs";
|
|
1
|
+
export { useLocalePath, useRouteBaseName, useSetI18nParams, useSwitchLocalePath } from "#build/content-i18n.mjs";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
declare module '#build/content-i18n.mjs' {
|
|
2
|
+
export function useLocalePath(): (route: string | { name?: string, hash?: string, params?: Record<string, unknown>, query?: Record<string, unknown> }, locale?: string) => string
|
|
2
3
|
export function useRouteBaseName(): (route: { name?: unknown } | unknown) => string | undefined
|
|
3
4
|
export function useSetI18nParams(): (params: Record<string, unknown>) => void
|
|
4
5
|
export function useSwitchLocalePath(): (locale: string) => string
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { collectMarkdownRefLinks, parseRefLink } from "../core/references/resolve";
|
|
2
|
+
import { projectContentPathToLocale } from "../features/localization/path";
|
|
2
3
|
import { contentConfig } from "./driver.js";
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
if (!
|
|
7
|
-
return
|
|
4
|
+
import { resolveCanonicalKey, resolveVariant } from "./manifest.js";
|
|
5
|
+
const isConfiguredQuickLink = (href) => {
|
|
6
|
+
const parsed = parseRefLink(href);
|
|
7
|
+
if (!parsed) {
|
|
8
|
+
return false;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
const separator = parsed.ref.indexOf(".");
|
|
11
|
+
if (separator <= 0 || separator === parsed.ref.length - 1) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const namespace = parsed.ref.slice(0, separator);
|
|
15
|
+
const key = parsed.ref.slice(separator + 1);
|
|
16
|
+
const links = contentConfig().links;
|
|
17
|
+
return Boolean(links?.[namespace]?.[key]);
|
|
10
18
|
};
|
|
11
19
|
const resolveDocumentRefLinks = async (event, content, requestedLocale) => {
|
|
12
20
|
if (!content || content._type !== "markdown" || !content.body) {
|
|
@@ -16,14 +24,16 @@ const resolveDocumentRefLinks = async (event, content, requestedLocale) => {
|
|
|
16
24
|
if (!hrefs.length) {
|
|
17
25
|
return void 0;
|
|
18
26
|
}
|
|
19
|
-
const manifest = await getContentManifest(event);
|
|
20
27
|
const entries = await Promise.all(hrefs.map(async (href) => {
|
|
21
28
|
const parsed = parseRefLink(href);
|
|
22
29
|
if (!parsed) {
|
|
23
30
|
return null;
|
|
24
31
|
}
|
|
25
|
-
const canonicalKey =
|
|
32
|
+
const canonicalKey = await resolveCanonicalKey(event, parsed.ref);
|
|
26
33
|
if (!canonicalKey) {
|
|
34
|
+
if (isConfiguredQuickLink(href)) {
|
|
35
|
+
return [href, href];
|
|
36
|
+
}
|
|
27
37
|
if (import.meta.dev) {
|
|
28
38
|
console.warn(`[content] Could not resolve markdown ref "${href}" in "${content._file || content._id}"`);
|
|
29
39
|
}
|
|
@@ -39,7 +49,8 @@ const resolveDocumentRefLinks = async (event, content, requestedLocale) => {
|
|
|
39
49
|
if (import.meta.dev && requestedLocale && variant.resolvedLocale && variant.resolvedLocale !== requestedLocale) {
|
|
40
50
|
console.warn(`[content] Markdown ref "${href}" in "${content._file || content._id}" fell back from locale "${requestedLocale}" to "${variant.resolvedLocale}"`);
|
|
41
51
|
}
|
|
42
|
-
|
|
52
|
+
const routeLocale = variant.fallback && requestedLocale ? requestedLocale : variant.resolvedLocale;
|
|
53
|
+
return [href, `${projectContentPathToLocale(variant.path, routeLocale, contentConfig().defaultLocale)}${parsed.hash}`];
|
|
43
54
|
}));
|
|
44
55
|
const resolvedRefs = Object.fromEntries(entries.filter((entry) => Boolean(entry)));
|
|
45
56
|
return Object.keys(resolvedRefs).length ? resolvedRefs : void 0;
|
package/dist/types/module.d.ts
CHANGED
|
@@ -264,6 +264,21 @@ export interface ContentRevalidateOptions {
|
|
|
264
264
|
*/
|
|
265
265
|
allowUnsigned?: boolean;
|
|
266
266
|
}
|
|
267
|
+
export interface ContentLinkRouteTarget {
|
|
268
|
+
/**
|
|
269
|
+
* Nuxt route name passed to Nuxt I18n `localePath()`.
|
|
270
|
+
*/
|
|
271
|
+
route: string;
|
|
272
|
+
/**
|
|
273
|
+
* Static route params forwarded to Nuxt I18n `localePath()`.
|
|
274
|
+
*/
|
|
275
|
+
params?: Record<string, string | number>;
|
|
276
|
+
/**
|
|
277
|
+
* Static query params forwarded to Nuxt I18n `localePath()`.
|
|
278
|
+
*/
|
|
279
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
280
|
+
}
|
|
281
|
+
export type ContentLinksOptions = Record<string, Record<string, ContentLinkRouteTarget>>;
|
|
267
282
|
export interface ContentAgentRouteOptions {
|
|
268
283
|
routes?: boolean;
|
|
269
284
|
linkHeaders?: boolean;
|
|
@@ -313,6 +328,15 @@ export interface ModuleOptions {
|
|
|
313
328
|
* `x-ginko-revalidate-token` or `authorization: Bearer <token>`.
|
|
314
329
|
*/
|
|
315
330
|
revalidate?: false | ContentRevalidateOptions;
|
|
331
|
+
/**
|
|
332
|
+
* Writer-facing markdown quick links. Values point at Nuxt route names;
|
|
333
|
+
* localized paths stay owned by Nuxt I18n.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* content.links.main.pricing = { route: 'pricing' }
|
|
337
|
+
* markdown: [Pricing]($main.pricing)
|
|
338
|
+
*/
|
|
339
|
+
links?: ContentLinksOptions;
|
|
316
340
|
/**
|
|
317
341
|
* First-class agent markdown and LLM route features.
|
|
318
342
|
*/
|
package/dist/types.d.mts
CHANGED
|
@@ -8,4 +8,4 @@ export { type agentMetadataFields, type defineAgentAppPage, type defineAgentMark
|
|
|
8
8
|
|
|
9
9
|
export { default, type normalizeContentConfigCollectionNames } from './module.mjs'
|
|
10
10
|
|
|
11
|
-
export { type AgentMetadataField, type AgentMetadataFieldList, type BacklinkFields, type BacklinkSource, type BacklinksOptions, type BacklinksResult, type CollectionQueryBuilder, type CollectionQueryField, type CollectionQueryFieldValue, type CollectionQueryKey, type CollectionQueryOperator, type CollectionQueryValue, type CollectionSchema, type ContentAgentAppPageConfig, type ContentAgentAppPageContext, type ContentAgentCollectionConfig, type ContentAgentConfig, type ContentAgentLocalizedValue, type ContentAgentMarkdownMetadataConfig, type ContentAgentMarkdownOptions, type ContentAgentMarkdownPolicyConfig, type ContentAgentRouteOptions, type ContentAgentSectionConfig, type ContentAgentSiteConfig, type ContentCacheArtifact, type ContentCmsCollectionConfig, type ContentCmsFieldConfig, type ContentCmsFieldType, type ContentCmsRelationConfig, type ContentCollectionConfig, type ContentCollectionHandle, type ContentCollectionI18nConfig, type ContentCollectionI18nMap, type ContentCollectionItem, type ContentCollectionItemSurroundingsOptions, type ContentCollectionKind, type ContentCollectionMap, type ContentCollectionName, type ContentCollectionNavigationOptions, type ContentCollectionPageOptions, type ContentCollectionRouteConfig, type ContentCollectionRouteMetaOptions, type ContentCollectionSearchSectionsOptions, type ContentCollectionSource, type ContentCollectionSourceObject, type ContentCollectionStringName, type ContentCollectionTarget, type ContentConfig, type ContentContext, type ContentI18nOptions, type ContentLocaleEntry, type ContentLocaleRoute, type ContentManifest, type ContentMiniSearchOptions, type ContentNavigationItem, type ContentPageResult, type ContentPreviewOptions, type ContentProviderName, type ContentProviderSearchRequest, type ContentQueryBuilder, type ContentQueryBuilderParams, type ContentQueryBuilderWhere, type ContentQueryFetcher, type ContentQueryRequest, type ContentQuerySortFields, type ContentQuerySortOptions, type ContentQuerySortParams, type ContentReferenceSchema, type ContentResolvedMeta, type ContentRevalidateOptions, type ContentRouteMeta, type ContentSearchEngine, type ContentSearchIndexRecord, type ContentSearchOptions, type ContentSearchPublicRuntimeConfig, type ContentSearchResult, type ContentSearchSection, type ContentSelector, type ContentSeoImage, type ContentSeoMeta, type ContentSitemapAlternative, type ContentSitemapAssertOptions, type ContentSitemapAssertSitemapOptions, type ContentSitemapEntry, type ContentSitemapImage, type ContentSitemapOptions, type ContentTransformer, type ContentTreeItem, type ContentVariant, type DefineCollectionObject, type DefineCollectionOptions, type DocumentFromHandle, type LocaleFallback, type LocalePathEntry, type LocalizedContentDocument, type LocalizedDoc, type ManifestVariant, type ManyOptions, type MarkdownNode, type MarkdownOptions, type MarkdownParsedContent, type MarkdownPluginDescriptor, type MarkdownPluginOptions, type MarkdownRoot, type ModuleHooks, type ModuleOptions, type MountOptions, type NavItem, type NeighborsOptions, type NeighborsResult, type OneOptions, type PaginationOptions, type PaginationResult, type ParseContentOptions, type ParsedContent, type ParsedContentInternalMeta, type ParsedContentMeta, type PopulateFromOptions, type PopulateSpec, type PopulatedDocument, type QueryGroupBuilder, type QueryGroupFunction, type QueryMatchOperator, type QueryOperators, type QueryOrderDirection, type QueryOrderOptions, type QueryWhere, type ResolutionEnvelope, type ResolveContentReferenceOptions, type ResolveOneOptions, type ResolveOneResult, type ResolvedContentContext, type ResolvedContentI18nOptions, type ResolvedMarkdownPlugin, type ResolvedVariant, type SortDirection, type SortSpec, type StrictParsedContent, type StrictParsedContentMeta, type Toc, type TocLink, type TransformContentOptions, type TransformContentSource, type TreeOptions, type VariantsOptions } from './module.mjs'
|
|
11
|
+
export { type AgentMetadataField, type AgentMetadataFieldList, type BacklinkFields, type BacklinkSource, type BacklinksOptions, type BacklinksResult, type CollectionQueryBuilder, type CollectionQueryField, type CollectionQueryFieldValue, type CollectionQueryKey, type CollectionQueryOperator, type CollectionQueryValue, type CollectionSchema, type ContentAgentAppPageConfig, type ContentAgentAppPageContext, type ContentAgentCollectionConfig, type ContentAgentConfig, type ContentAgentLocalizedValue, type ContentAgentMarkdownMetadataConfig, type ContentAgentMarkdownOptions, type ContentAgentMarkdownPolicyConfig, type ContentAgentRouteOptions, type ContentAgentSectionConfig, type ContentAgentSiteConfig, type ContentCacheArtifact, type ContentCmsCollectionConfig, type ContentCmsFieldConfig, type ContentCmsFieldType, type ContentCmsRelationConfig, type ContentCollectionConfig, type ContentCollectionHandle, type ContentCollectionI18nConfig, type ContentCollectionI18nMap, type ContentCollectionItem, type ContentCollectionItemSurroundingsOptions, type ContentCollectionKind, type ContentCollectionMap, type ContentCollectionName, type ContentCollectionNavigationOptions, type ContentCollectionPageOptions, type ContentCollectionRouteConfig, type ContentCollectionRouteMetaOptions, type ContentCollectionSearchSectionsOptions, type ContentCollectionSource, type ContentCollectionSourceObject, type ContentCollectionStringName, type ContentCollectionTarget, type ContentConfig, type ContentContext, type ContentI18nOptions, type ContentLinkRouteTarget, type ContentLinksOptions, type ContentLocaleEntry, type ContentLocaleRoute, type ContentManifest, type ContentMiniSearchOptions, type ContentNavigationItem, type ContentPageResult, type ContentPreviewOptions, type ContentProviderName, type ContentProviderSearchRequest, type ContentQueryBuilder, type ContentQueryBuilderParams, type ContentQueryBuilderWhere, type ContentQueryFetcher, type ContentQueryRequest, type ContentQuerySortFields, type ContentQuerySortOptions, type ContentQuerySortParams, type ContentReferenceSchema, type ContentResolvedMeta, type ContentRevalidateOptions, type ContentRouteMeta, type ContentSearchEngine, type ContentSearchIndexRecord, type ContentSearchOptions, type ContentSearchPublicRuntimeConfig, type ContentSearchResult, type ContentSearchSection, type ContentSelector, type ContentSeoImage, type ContentSeoMeta, type ContentSitemapAlternative, type ContentSitemapAssertOptions, type ContentSitemapAssertSitemapOptions, type ContentSitemapEntry, type ContentSitemapImage, type ContentSitemapOptions, type ContentTransformer, type ContentTreeItem, type ContentVariant, type DefineCollectionObject, type DefineCollectionOptions, type DocumentFromHandle, type LocaleFallback, type LocalePathEntry, type LocalizedContentDocument, type LocalizedDoc, type ManifestVariant, type ManyOptions, type MarkdownNode, type MarkdownOptions, type MarkdownParsedContent, type MarkdownPluginDescriptor, type MarkdownPluginOptions, type MarkdownRoot, type ModuleHooks, type ModuleOptions, type MountOptions, type NavItem, type NeighborsOptions, type NeighborsResult, type OneOptions, type PaginationOptions, type PaginationResult, type ParseContentOptions, type ParsedContent, type ParsedContentInternalMeta, type ParsedContentMeta, type PopulateFromOptions, type PopulateSpec, type PopulatedDocument, type QueryGroupBuilder, type QueryGroupFunction, type QueryMatchOperator, type QueryOperators, type QueryOrderDirection, type QueryOrderOptions, type QueryWhere, type ResolutionEnvelope, type ResolveContentReferenceOptions, type ResolveOneOptions, type ResolveOneResult, type ResolvedContentContext, type ResolvedContentI18nOptions, type ResolvedMarkdownPlugin, type ResolvedVariant, type SortDirection, type SortSpec, type StrictParsedContent, type StrictParsedContentMeta, type Toc, type TocLink, type TransformContentOptions, type TransformContentSource, type TreeOptions, type VariantsOptions } from './module.mjs'
|
package/dist/web-types.json
CHANGED