@ingram-tech/nk-blog 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/rss.d.ts.map +1 -1
- package/dist/rss.js +4 -2
- package/dist/rss.js.map +1 -1
- package/dist/seo.d.ts.map +1 -1
- package/dist/seo.js +9 -7
- package/dist/seo.js.map +1 -1
- package/package.json +6 -6
- package/src/rss.ts +4 -2
- package/src/seo.ts +11 -10
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ URLs: default-language posts live at `basePath`, others at `/<lang><basePath>`
|
|
|
97
97
|
(nk-i18n's prefix shape). Unlike nk-i18n's negotiated pages the default
|
|
98
98
|
language is not prefixed: a post is one document in one language with exactly
|
|
99
99
|
one address, so there is no language-neutral bare URL to reserve. Route the
|
|
100
|
-
other languages with a `[lang]` segment (`app/[lang]/blog/[slug]/page.tsx`,
|
|
100
|
+
other languages with a `[lang]` segment (`src/app/[lang]/blog/[slug]/page.tsx`,
|
|
101
101
|
`generateStaticParams` over `blog.posts()` minus the default language) so the
|
|
102
102
|
posts stay fully static. `blogPostArticle` sets `inLanguage`; a per-language
|
|
103
103
|
feed is `generateRss({ ...config, basePath: "/fr/blog", language: "fr" },
|
package/dist/rss.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rss.d.ts","sourceRoot":"","sources":["../src/rss.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAaD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"rss.d.ts","sourceRoot":"","sources":["../src/rss.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAaD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,CA2C/E"}
|
package/dist/rss.js
CHANGED
|
@@ -12,9 +12,11 @@ const escapeXml = (value) => value
|
|
|
12
12
|
* with `export const dynamic = "force-static"`) so it renders at build.
|
|
13
13
|
*/
|
|
14
14
|
export function generateRss(config, posts) {
|
|
15
|
+
// A trailing-slash siteUrl would otherwise join into `https://x.com//posts`.
|
|
16
|
+
const blogUrl = `${config.siteUrl.replace(/\/+$/, "")}${config.basePath}`;
|
|
15
17
|
const items = posts
|
|
16
18
|
.map((post) => {
|
|
17
|
-
const url = `${
|
|
19
|
+
const url = `${blogUrl}/${post.slug}`;
|
|
18
20
|
return [
|
|
19
21
|
"\t\t<item>",
|
|
20
22
|
`\t\t\t<title>${escapeXml(post.title)}</title>`,
|
|
@@ -35,7 +37,7 @@ export function generateRss(config, posts) {
|
|
|
35
37
|
'<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">',
|
|
36
38
|
"\t<channel>",
|
|
37
39
|
`\t\t<title>${escapeXml(config.title)}</title>`,
|
|
38
|
-
`\t\t<link>${escapeXml(
|
|
40
|
+
`\t\t<link>${escapeXml(blogUrl)}</link>`,
|
|
39
41
|
`\t\t<description>${escapeXml(config.description ?? config.title)}</description>`,
|
|
40
42
|
`\t\t<language>${escapeXml(config.language ?? "en")}</language>`,
|
|
41
43
|
`\t\t<atom:link href="${escapeXml(config.feedUrl)}" rel="self" type="application/rss+xml"/>`,
|
package/dist/rss.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rss.js","sourceRoot":"","sources":["../src/rss.ts"],"names":[],"mappings":"AAcA,MAAM,SAAS,GAAG,CAAC,KAAa,EAAU,EAAE,CAC3C,KAAK;IACJ,sEAAsE;IACtE,gEAAgE;IAChE,wFAAwF;KACvF,OAAO,CAAC,2CAA2C,EAAE,EAAE,CAAC;KACxD,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;KACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;KACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;KACvB,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,MAAiB,EAAE,KAAwB;IACtE,MAAM,KAAK,GAAG,KAAK;SACjB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,MAAM,GAAG,GAAG,GAAG,
|
|
1
|
+
{"version":3,"file":"rss.js","sourceRoot":"","sources":["../src/rss.ts"],"names":[],"mappings":"AAcA,MAAM,SAAS,GAAG,CAAC,KAAa,EAAU,EAAE,CAC3C,KAAK;IACJ,sEAAsE;IACtE,gEAAgE;IAChE,wFAAwF;KACvF,OAAO,CAAC,2CAA2C,EAAE,EAAE,CAAC;KACxD,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;KACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;KACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;KACvB,UAAU,CA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AoB,SAAS,CAAC,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,KAAK,CAAC,gBAAgB;QACjF,iBAAiB,SAAS,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC,aAAa;QAChE,wBAAwB,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,2CAA2C;QAC5F,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACX,CAAC,CAAC;gBACA,sBAAsB,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,kBAAkB;aAC7E;YACF,CAAC,CAAC,EAAE,CAAC;QACN,KAAK;QACL,cAAc;QACd,QAAQ;QACR,EAAE;KACF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC"}
|
package/dist/seo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../src/seo.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,WAAW,aAAa;IAC7B,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;;;;OAUG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../src/seo.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK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CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { article, breadcrumbList, } from "@ingram-tech/nk-seo";
|
|
2
|
+
/** The configured origin without a trailing slash, so joins never emit `//`. */
|
|
3
|
+
const siteOrigin = (config) => config.baseUrl.replace(/\/+$/, "");
|
|
2
4
|
/** `/fr` for a non-default language, `""` for the default (or no language). */
|
|
3
5
|
const langPrefix = (lang, config) => config.defaultLang !== undefined &&
|
|
4
6
|
lang !== undefined &&
|
|
@@ -7,7 +9,7 @@ const langPrefix = (lang, config) => config.defaultLang !== undefined &&
|
|
|
7
9
|
: "";
|
|
8
10
|
/** Absolute URL of the blog index in `lang`: `/blog`, `/fr/blog`. */
|
|
9
11
|
export function blogIndexUrl(lang, config) {
|
|
10
|
-
return `${config
|
|
12
|
+
return `${siteOrigin(config)}${langPrefix(lang, config)}${config.basePath}`;
|
|
11
13
|
}
|
|
12
14
|
/** Absolute URL of a post, prefixed by its language when that isn't the default. */
|
|
13
15
|
export function postUrl(post, config) {
|
|
@@ -19,7 +21,7 @@ export function postUrl(post, config) {
|
|
|
19
21
|
* exist, so a French-only article never advertises an English URL.
|
|
20
22
|
*/
|
|
21
23
|
export function blogPostAlternates(post, translations, config) {
|
|
22
|
-
const canonical = toAbsoluteUrl(post.canonical ?? postUrl(post, config), config
|
|
24
|
+
const canonical = toAbsoluteUrl(post.canonical ?? postUrl(post, config), config);
|
|
23
25
|
const versions = translations.filter((version) => version.lang !== undefined);
|
|
24
26
|
if (versions.length < 2)
|
|
25
27
|
return { canonical, languages: {} };
|
|
@@ -39,20 +41,20 @@ export function blogPostAlternates(post, translations, config) {
|
|
|
39
41
|
// rather than being origin-checked: a post's image can live on a CDN and its
|
|
40
42
|
// `canonical` can be a cross-origin syndication override, both legitimately
|
|
41
43
|
// off-origin — so this must not throw the way the canonical-link resolver does.
|
|
42
|
-
const toAbsoluteUrl = (url,
|
|
44
|
+
const toAbsoluteUrl = (url, config) => /^https?:\/\//.test(url)
|
|
43
45
|
? url
|
|
44
|
-
: `${
|
|
46
|
+
: `${siteOrigin(config)}${url.startsWith("/") ? "" : "/"}${url}`;
|
|
45
47
|
/** BlogPosting JSON-LD for a post — the nk-seo bridge. */
|
|
46
48
|
export function blogPostArticle(post, config, overrides = {}) {
|
|
47
49
|
return article({
|
|
48
50
|
type: "BlogPosting",
|
|
49
51
|
headline: post.title,
|
|
50
52
|
description: post.description,
|
|
51
|
-
url: toAbsoluteUrl(post.canonical ?? postUrl(post, config), config
|
|
53
|
+
url: toAbsoluteUrl(post.canonical ?? postUrl(post, config), config),
|
|
52
54
|
datePublished: post.date,
|
|
53
55
|
dateModified: post.updated,
|
|
54
56
|
authors: post.authors.map((name) => ({ name })),
|
|
55
|
-
image: post.image ? toAbsoluteUrl(post.image, config
|
|
57
|
+
image: post.image ? toAbsoluteUrl(post.image, config) : undefined,
|
|
56
58
|
keywords: post.tags.length ? post.tags : undefined,
|
|
57
59
|
publisher: config.publisher,
|
|
58
60
|
...(post.lang ? { extra: { inLanguage: post.lang } } : {}),
|
|
@@ -62,7 +64,7 @@ export function blogPostArticle(post, config, overrides = {}) {
|
|
|
62
64
|
/** Home → Blog → Post breadcrumb JSON-LD. */
|
|
63
65
|
export function blogPostBreadcrumbs(post, config) {
|
|
64
66
|
return breadcrumbList([
|
|
65
|
-
{ name: "Home", url: `${config
|
|
67
|
+
{ name: "Home", url: `${siteOrigin(config)}${langPrefix(post.lang, config)}` },
|
|
66
68
|
{ name: config.blogName ?? "Blog", url: blogIndexUrl(post.lang, config) },
|
|
67
69
|
{ name: post.title, url: postUrl(post, config) },
|
|
68
70
|
]);
|
package/dist/seo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seo.js","sourceRoot":"","sources":["../src/seo.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EAGP,cAAc,GAId,MAAM,qBAAqB,CAAC;AA0B7B,+EAA+E;AAC/E,MAAM,UAAU,GAAG,CAAC,IAAwB,EAAE,MAAq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AAM,CAAC,EAAE,EAAE;QAC9E,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM,EAAE,GAAG,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;QACzE,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE;KAChD,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-blog",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "File-based blog foundation for Next.js sites: frontmatter schema, build-time reader, limited-MDX rendering, a typed component contract with unstyled defaults, GitHub read/publish, and RSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test": "vitest run"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ingram-tech/nk-seo": "^0.10.
|
|
46
|
+
"@ingram-tech/nk-seo": "^0.10.3",
|
|
47
47
|
"@mdx-js/mdx": "^3.1.1",
|
|
48
48
|
"gray-matter": "^4.0.3",
|
|
49
49
|
"react-markdown": "^10.1.0",
|
|
@@ -64,18 +64,18 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@ingram-tech/nk-dev": "0.
|
|
67
|
+
"@ingram-tech/nk-dev": "0.20.0",
|
|
68
68
|
"@types/mdast": "^4.0.4",
|
|
69
|
-
"@types/node": "^26.5
|
|
69
|
+
"@types/node": "^26.6.5",
|
|
70
70
|
"@types/react": "^19.3.0",
|
|
71
71
|
"@types/react-dom": "^19.3.0",
|
|
72
72
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
73
|
-
"next": "^16.
|
|
73
|
+
"next": "^16.4.0",
|
|
74
74
|
"react": "^19.3.0",
|
|
75
75
|
"react-dom": "^19.3.0",
|
|
76
76
|
"typescript": "^7.0.2",
|
|
77
77
|
"unified": "^11.0.5",
|
|
78
78
|
"vfile": "^6.0.3",
|
|
79
|
-
"vitest": "^5.0.
|
|
79
|
+
"vitest": "^5.0.3"
|
|
80
80
|
}
|
|
81
81
|
}
|
package/src/rss.ts
CHANGED
|
@@ -28,9 +28,11 @@ const escapeXml = (value: string): string =>
|
|
|
28
28
|
* with `export const dynamic = "force-static"`) so it renders at build.
|
|
29
29
|
*/
|
|
30
30
|
export function generateRss(config: RssConfig, posts: BlogPostPreview[]): string {
|
|
31
|
+
// A trailing-slash siteUrl would otherwise join into `https://x.com//posts`.
|
|
32
|
+
const blogUrl = `${config.siteUrl.replace(/\/+$/, "")}${config.basePath}`;
|
|
31
33
|
const items = posts
|
|
32
34
|
.map((post) => {
|
|
33
|
-
const url = `${
|
|
35
|
+
const url = `${blogUrl}/${post.slug}`;
|
|
34
36
|
return [
|
|
35
37
|
"\t\t<item>",
|
|
36
38
|
`\t\t\t<title>${escapeXml(post.title)}</title>`,
|
|
@@ -54,7 +56,7 @@ export function generateRss(config: RssConfig, posts: BlogPostPreview[]): string
|
|
|
54
56
|
'<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">',
|
|
55
57
|
"\t<channel>",
|
|
56
58
|
`\t\t<title>${escapeXml(config.title)}</title>`,
|
|
57
|
-
`\t\t<link>${escapeXml(
|
|
59
|
+
`\t\t<link>${escapeXml(blogUrl)}</link>`,
|
|
58
60
|
`\t\t<description>${escapeXml(config.description ?? config.title)}</description>`,
|
|
59
61
|
`\t\t<language>${escapeXml(config.language ?? "en")}</language>`,
|
|
60
62
|
`\t\t<atom:link href="${escapeXml(config.feedUrl)}" rel="self" type="application/rss+xml"/>`,
|
package/src/seo.ts
CHANGED
|
@@ -32,6 +32,10 @@ export interface BlogSeoConfig {
|
|
|
32
32
|
defaultLang?: string;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/** The configured origin without a trailing slash, so joins never emit `//`. */
|
|
36
|
+
const siteOrigin = (config: BlogSeoConfig): string =>
|
|
37
|
+
config.baseUrl.replace(/\/+$/, "");
|
|
38
|
+
|
|
35
39
|
/** `/fr` for a non-default language, `""` for the default (or no language). */
|
|
36
40
|
const langPrefix = (lang: string | undefined, config: BlogSeoConfig): string =>
|
|
37
41
|
config.defaultLang !== undefined &&
|
|
@@ -42,7 +46,7 @@ const langPrefix = (lang: string | undefined, config: BlogSeoConfig): string =>
|
|
|
42
46
|
|
|
43
47
|
/** Absolute URL of the blog index in `lang`: `/blog`, `/fr/blog`. */
|
|
44
48
|
export function blogIndexUrl(lang: string | undefined, config: BlogSeoConfig): string {
|
|
45
|
-
return `${config
|
|
49
|
+
return `${siteOrigin(config)}${langPrefix(lang, config)}${config.basePath}`;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
/** Absolute URL of a post, prefixed by its language when that isn't the default. */
|
|
@@ -71,10 +75,7 @@ export function blogPostAlternates(
|
|
|
71
75
|
translations: readonly BlogPostPreview[],
|
|
72
76
|
config: BlogSeoConfig,
|
|
73
77
|
): BlogPostAlternates {
|
|
74
|
-
const canonical = toAbsoluteUrl(
|
|
75
|
-
post.canonical ?? postUrl(post, config),
|
|
76
|
-
config.baseUrl,
|
|
77
|
-
);
|
|
78
|
+
const canonical = toAbsoluteUrl(post.canonical ?? postUrl(post, config), config);
|
|
78
79
|
const versions = translations.filter((version) => version.lang !== undefined);
|
|
79
80
|
if (versions.length < 2) return { canonical, languages: {} };
|
|
80
81
|
|
|
@@ -93,10 +94,10 @@ export function blogPostAlternates(
|
|
|
93
94
|
// rather than being origin-checked: a post's image can live on a CDN and its
|
|
94
95
|
// `canonical` can be a cross-origin syndication override, both legitimately
|
|
95
96
|
// off-origin — so this must not throw the way the canonical-link resolver does.
|
|
96
|
-
const toAbsoluteUrl = (url: string,
|
|
97
|
+
const toAbsoluteUrl = (url: string, config: BlogSeoConfig): string =>
|
|
97
98
|
/^https?:\/\//.test(url)
|
|
98
99
|
? url
|
|
99
|
-
: `${
|
|
100
|
+
: `${siteOrigin(config)}${url.startsWith("/") ? "" : "/"}${url}`;
|
|
100
101
|
|
|
101
102
|
/** BlogPosting JSON-LD for a post — the nk-seo bridge. */
|
|
102
103
|
export function blogPostArticle(
|
|
@@ -108,11 +109,11 @@ export function blogPostArticle(
|
|
|
108
109
|
type: "BlogPosting",
|
|
109
110
|
headline: post.title,
|
|
110
111
|
description: post.description,
|
|
111
|
-
url: toAbsoluteUrl(post.canonical ?? postUrl(post, config), config
|
|
112
|
+
url: toAbsoluteUrl(post.canonical ?? postUrl(post, config), config),
|
|
112
113
|
datePublished: post.date,
|
|
113
114
|
dateModified: post.updated,
|
|
114
115
|
authors: post.authors.map((name) => ({ name })),
|
|
115
|
-
image: post.image ? toAbsoluteUrl(post.image, config
|
|
116
|
+
image: post.image ? toAbsoluteUrl(post.image, config) : undefined,
|
|
116
117
|
keywords: post.tags.length ? post.tags : undefined,
|
|
117
118
|
publisher: config.publisher,
|
|
118
119
|
...(post.lang ? { extra: { inLanguage: post.lang } } : {}),
|
|
@@ -126,7 +127,7 @@ export function blogPostBreadcrumbs(
|
|
|
126
127
|
config: BlogSeoConfig,
|
|
127
128
|
): WithContext<BreadcrumbListNode> {
|
|
128
129
|
return breadcrumbList([
|
|
129
|
-
{ name: "Home", url: `${config
|
|
130
|
+
{ name: "Home", url: `${siteOrigin(config)}${langPrefix(post.lang, config)}` },
|
|
130
131
|
{ name: config.blogName ?? "Blog", url: blogIndexUrl(post.lang, config) },
|
|
131
132
|
{ name: post.title, url: postUrl(post, config) },
|
|
132
133
|
]);
|