Skip to content

Commit 8c74733

Browse files
committed
Add theme color to meta
1 parent ea3ae94 commit 8c74733

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tools/importer/import.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,25 @@ function getBreadcrumbs(html, pathname) {
7070
return breadcrumbs;
7171
}
7272

73+
function getThemeColor(html) {
74+
const themeColorRegex = /--theme-color: (#[0-9a-fA-F]{6});/g;
75+
const themeColorMatch = themeColorRegex.exec(html);
76+
77+
return themeColorMatch[1];
78+
}
79+
7380
const preprocessMetadata = {};
7481

7582
function createMetadata(main, document, pathname, html) {
7683
const meta = preprocessMetadata;
7784

7885
const urlInfo = urls.find(({ URL: url }) => (new URL(url).pathname) === pathname);
7986
meta.Theme = urlInfo.Theme;
87+
const themeColor = getThemeColor(html);
88+
report.themeColor = themeColor;
89+
if (themeColor !== '') {
90+
meta.ThemeColor = themeColor;
91+
}
8092
theme = meta.Theme;
8193

8294
meta.Title = document.querySelector('meta[property="og:title"]').content;
@@ -853,9 +865,7 @@ function findIcon(iconNode) {
853865
}
854866

855867
function inlineIcons(main, html) {
856-
const themeColorRegex = /--theme-color: (#[0-9a-fA-F]{6});/g;
857-
const themeColorMatch = themeColorRegex.exec(html);
858-
const themeColor = themeColorMatch[1];
868+
const themeColor = getThemeColor(html);
859869

860870
const foundIcons = [];
861871
const notFoundIcons = [];

0 commit comments

Comments
 (0)