czon 0.9.9 → 0.9.10
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/dist/ssg/IndexPage.js +19 -2
- package/dist/ssg/IndexPage.test.js +31 -0
- package/package.json +1 -1
package/dist/ssg/IndexPage.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IndexPage = void 0;
|
|
6
|
+
exports.IndexPage = exports.buildIndexPageTitle = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const sortBy_1 = require("../utils/sortBy");
|
|
9
9
|
const getCategoryDisplayName_1 = require("./utils/getCategoryDisplayName");
|
|
@@ -15,6 +15,14 @@ const LanguageSwitcher_1 = require("./components/LanguageSwitcher");
|
|
|
15
15
|
const PageLayout_1 = require("./layouts/PageLayout");
|
|
16
16
|
const resourceMap_1 = require("./resourceMap");
|
|
17
17
|
const style_1 = require("./style");
|
|
18
|
+
const buildIndexPageTitle = (params) => {
|
|
19
|
+
const safeSiteTitle = params.siteTitle?.trim() || 'CZON';
|
|
20
|
+
if (params.categoryDisplayName) {
|
|
21
|
+
return `${safeSiteTitle} - ${params.categoryDisplayName}`;
|
|
22
|
+
}
|
|
23
|
+
return `${safeSiteTitle} - Index of ${params.lang}`;
|
|
24
|
+
};
|
|
25
|
+
exports.buildIndexPageTitle = buildIndexPageTitle;
|
|
18
26
|
const IndexPage = props => {
|
|
19
27
|
const contents = (0, sortBy_1.toSortedBy)(props.ctx.site.files.filter(f => f.metadata && (!props.category || f.category === props.category)), [
|
|
20
28
|
// 无日期的排前面
|
|
@@ -25,10 +33,19 @@ const IndexPage = props => {
|
|
|
25
33
|
const allCategories = Array.from(new Set([undefined].concat(props.ctx.site.files.map(f => f.category))));
|
|
26
34
|
const faviconUrl = (0, resourceMap_1.getFaviconUrlFrom)(props.ctx.path);
|
|
27
35
|
const customStyleUrl = props.ctx.hasCustomStyle ? (0, resourceMap_1.getCustomStyleUrlFrom)(props.ctx.path) : null;
|
|
36
|
+
const siteTitle = props.ctx.site.options.site?.title;
|
|
37
|
+
const categoryDisplayName = props.category
|
|
38
|
+
? (0, getCategoryDisplayName_1.getCategoryDisplayName)(props.ctx.site, props.category, props.lang)
|
|
39
|
+
: undefined;
|
|
40
|
+
const pageTitle = (0, exports.buildIndexPageTitle)({
|
|
41
|
+
siteTitle,
|
|
42
|
+
lang: props.lang,
|
|
43
|
+
categoryDisplayName,
|
|
44
|
+
});
|
|
28
45
|
return (react_1.default.createElement("html", null,
|
|
29
46
|
react_1.default.createElement("head", null,
|
|
30
47
|
react_1.default.createElement("meta", { charSet: "UTF-8" }),
|
|
31
|
-
react_1.default.createElement("title", null,
|
|
48
|
+
react_1.default.createElement("title", null, pageTitle),
|
|
32
49
|
react_1.default.createElement("link", { rel: "icon", href: faviconUrl, type: "image/x-icon" }),
|
|
33
50
|
react_1.default.createElement("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" }),
|
|
34
51
|
react_1.default.createElement("meta", { name: "description", content: `Index page for language ${props.lang}` }),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
7
|
+
const node_test_1 = __importDefault(require("node:test"));
|
|
8
|
+
const IndexPage_1 = require("./IndexPage");
|
|
9
|
+
(0, node_test_1.default)('uses site title with language on index page', () => {
|
|
10
|
+
const title = (0, IndexPage_1.buildIndexPageTitle)({
|
|
11
|
+
siteTitle: 'My Docs',
|
|
12
|
+
lang: 'en',
|
|
13
|
+
});
|
|
14
|
+
strict_1.default.equal(title, 'My Docs - Index of en');
|
|
15
|
+
});
|
|
16
|
+
(0, node_test_1.default)('uses category title when category page is rendered', () => {
|
|
17
|
+
const title = (0, IndexPage_1.buildIndexPageTitle)({
|
|
18
|
+
siteTitle: 'My Docs',
|
|
19
|
+
lang: 'en',
|
|
20
|
+
categoryDisplayName: 'Guides',
|
|
21
|
+
});
|
|
22
|
+
strict_1.default.equal(title, 'My Docs - Guides');
|
|
23
|
+
});
|
|
24
|
+
(0, node_test_1.default)('falls back to CZON when site title is missing', () => {
|
|
25
|
+
const title = (0, IndexPage_1.buildIndexPageTitle)({
|
|
26
|
+
siteTitle: '',
|
|
27
|
+
lang: 'zh-Hans',
|
|
28
|
+
});
|
|
29
|
+
strict_1.default.equal(title, 'CZON - Index of zh-Hans');
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=IndexPage.test.js.map
|