hexo-theme-stellar/layout/_partial/head.ejs

134 lines
4.0 KiB
Plaintext
Raw Normal View History

2021-02-19 23:33:19 +08:00
<%
2021-02-21 04:01:17 +08:00
function generate_title() {
2022-11-06 19:46:47 +08:00
if (page.wiki) {
2024-01-19 01:05:44 +08:00
const proj = theme.wiki.tree[page.wiki]
const wiki = proj?.name || page.wiki
2022-11-06 19:46:47 +08:00
if (page.title) {
return wiki + __('symbol.colon') + page.title + ' - ' + config.title;
} else {
return wiki + ' - ' + config.title;
}
2021-02-19 23:33:19 +08:00
} else {
2022-11-07 21:51:45 +08:00
if (page.title) {
2022-11-19 16:48:44 +08:00
return page.title + ' - ' + config.title;
2022-11-07 21:51:45 +08:00
} else if (page.category) {
2022-11-06 19:46:47 +08:00
return __('btn.category') + __('symbol.colon') + page.category + ' - ' + config.title;
} else if (page.tag) {
return __('btn.tag') + __('symbol.colon') + page.tag + ' - ' + config.title;
}
2021-02-19 23:33:19 +08:00
}
2022-11-19 16:48:44 +08:00
return config.title;
2021-02-19 23:33:19 +08:00
}
2021-02-26 20:02:32 +08:00
function generate_description() {
2022-11-07 10:07:47 +08:00
if (theme.open_graph && theme.open_graph.enable) {
return '';
}
2024-01-13 21:10:26 +08:00
if (page.wiki) {
2024-01-19 01:05:44 +08:00
const proj = theme.wiki.tree[page.wiki]
if (proj?.description) {
return '<meta name="description" content="' + proj.description + '">'
2022-11-06 19:46:47 +08:00
}
2021-02-26 20:02:32 +08:00
}
if (page.description || page.excerpt || page.content) {
return '<meta name="description" content="' + truncate(strip_html(page.description || page.excerpt || page.content), {length: 150}) + '">';
}
return '<meta name="description" content="' + config.description + '">';
}
2023-03-29 12:40:02 +08:00
function generate_keywords() {
if (page.keywords && page.keywords.length > 0) {
return '<meta name="keywords" content="' + page.keywords + '">';
} else if (page.tags && page.tags.length > 0) {
return '<meta name="keywords" content="' + page.tags.map(tag => tag.name).join(',') + '">';
} else if (config.keywords && config.keywords.length > 0) {
return '<meta name="keywords" content="' + config.keywords + '">';
} else {
return '';
}
}
2021-02-26 20:02:32 +08:00
2021-02-21 04:01:17 +08:00
function generate_robots() {
if (is_home() == true) {
return '';
}
if (page.robots) {
return '<meta name="robots" content="' + page.robots + '">';
}
2021-02-19 23:33:19 +08:00
}
2021-02-21 03:13:21 +08:00
function og_args() {
var args = {};
if (theme.open_graph.twitter_id) {
args.twitter_id = theme.open_graph.twitter_id;
2021-02-19 23:33:19 +08:00
}
2021-02-21 03:13:21 +08:00
if (page.layout == 'post' && page.cover) {
args.twitter_card = 'summary_large_image';
2021-02-19 23:33:19 +08:00
}
2023-12-17 21:05:58 +08:00
return Object.assign(args, page.open_graph);
2021-02-19 23:33:19 +08:00
}
2024-01-04 13:39:50 +08:00
function preconnect() {
var el = '';
for (let href of (theme.preconnect || [])) {
el += `<link rel="preconnect" href="${href}" crossorigin>`;
}
return el;
}
function custom_inject() {
var el = '';
for (let item of (config.inject?.head || [])) {
el += item;
}
for (let item of (theme.inject?.head || [])) {
el += item;
}
for (let item of (page.inject?.head || [])) {
el += item;
}
return el;
}
2021-02-19 23:33:19 +08:00
%>
2024-01-04 13:39:50 +08:00
2021-03-06 00:01:41 +08:00
<head>
2021-02-19 23:33:19 +08:00
<meta charset="utf-8">
2024-01-08 12:04:07 +08:00
<meta name="hexo-theme" content="<%- stellar_info('tree') %>" theme-name="<%- stellar_info('name') %>" theme-version="<%- stellar_info('version') %>">
2021-02-21 04:01:17 +08:00
<%- generate_robots() %>
2024-01-04 13:39:50 +08:00
<%- meta_generator() %>
2021-02-19 23:33:19 +08:00
<meta http-equiv='x-dns-prefetch-control' content='on' />
2024-01-04 13:39:50 +08:00
<%- preconnect() %>
2021-02-19 23:33:19 +08:00
<meta name="renderer" content="webkit">
<meta name="force-rendering" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="HandheldFriendly" content="True" >
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#f9fafb">
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#1c1e21">
2022-10-29 17:23:32 +08:00
2021-02-21 04:01:17 +08:00
<title><%- generate_title() %></title>
2021-02-19 23:33:19 +08:00
2021-02-21 03:13:21 +08:00
<% if (theme.open_graph && theme.open_graph.enable) { %>
<%- open_graph(og_args()) %>
<% } %>
2021-02-26 20:02:32 +08:00
<%- generate_description() %>
2023-03-29 12:40:02 +08:00
<%- generate_keywords() %>
2021-02-19 23:33:19 +08:00
<!-- feed -->
<% if (config.feed && config.feed.path) { %>
<%- feed_tag(config.feed.path, {title: config.title}) %>
<% } %>
2024-01-22 13:22:40 +08:00
<link rel="stylesheet" href="<%- `${theme.stellar.main_css}?v=${stellar_info('version')}` %>">
2021-02-19 23:33:19 +08:00
2021-06-23 16:39:27 +08:00
<% if (config.favicon) { %>
<%- favicon_tag(config.favicon) %>
<% } %>
2021-07-26 22:26:46 +08:00
2022-06-07 13:19:56 +08:00
<% if (config.highlight && config.highlight.enable == true && config.highlight.hljs == true) { %>
<%- css(theme.style.codeblock.highlightjs_theme) %>
<% } %>
2024-01-04 13:39:50 +08:00
<%- custom_inject() %>
2021-02-19 23:33:19 +08:00
</head>