mirror of
https://github.com/fmhy/edit.git
synced 2026-02-07 11:41:05 +11:00
style: format with new style
This commit is contained in:
parent
bc3bbaafeb
commit
ef422dcda8
43 changed files with 686 additions and 583 deletions
|
|
@ -1,89 +1,100 @@
|
|||
import type { HeadConfig, TransformContext } from "vitepress";
|
||||
import type { HeadConfig, TransformContext } from 'vitepress'
|
||||
|
||||
export function generateMeta(context: TransformContext, hostname: string) {
|
||||
const head: HeadConfig[] = [];
|
||||
const { pageData } = context;
|
||||
const head: HeadConfig[] = []
|
||||
const { pageData } = context
|
||||
|
||||
const url = `${hostname}/${pageData.relativePath.replace(/((^|\/)index)?\.md$/, "$2")}`;
|
||||
const url = `${hostname}/${pageData.relativePath.replace(/((^|\/)index)?\.md$/, '$2')}`
|
||||
|
||||
head.push(
|
||||
["link", { rel: "canonical", href: url }],
|
||||
["meta", { property: "og:url", content: url }],
|
||||
["meta", { name: "twitter:url", content: url }],
|
||||
["meta", { name: "twitter:card", content: "summary_large_image" }],
|
||||
["meta", { property: "og:title", content: pageData.frontmatter.title }],
|
||||
["meta", { name: "twitter:title", content: pageData.frontmatter.title }],
|
||||
);
|
||||
['link', { rel: 'canonical', href: url }],
|
||||
['meta', { property: 'og:url', content: url }],
|
||||
['meta', { name: 'twitter:url', content: url }],
|
||||
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
|
||||
['meta', { property: 'og:title', content: pageData.frontmatter.title }],
|
||||
['meta', { name: 'twitter:title', content: pageData.frontmatter.title }]
|
||||
)
|
||||
if (pageData.frontmatter.description) {
|
||||
head.push(
|
||||
[
|
||||
"meta",
|
||||
'meta',
|
||||
{
|
||||
property: "og:description",
|
||||
content: pageData.frontmatter.description,
|
||||
},
|
||||
property: 'og:description',
|
||||
content: pageData.frontmatter.description
|
||||
}
|
||||
],
|
||||
[
|
||||
"meta",
|
||||
'meta',
|
||||
{
|
||||
name: "twitter:description",
|
||||
content: pageData.frontmatter.description,
|
||||
},
|
||||
],
|
||||
);
|
||||
name: 'twitter:description',
|
||||
content: pageData.frontmatter.description
|
||||
}
|
||||
]
|
||||
)
|
||||
}
|
||||
if (pageData.frontmatter.image) {
|
||||
head.push([
|
||||
"meta",
|
||||
'meta',
|
||||
{
|
||||
property: "og:image",
|
||||
content: `${hostname}/${pageData.frontmatter.image.replace(/^\//, "")}`,
|
||||
},
|
||||
]);
|
||||
property: 'og:image',
|
||||
content: `${hostname}/${pageData.frontmatter.image.replace(/^\//, '')}`
|
||||
}
|
||||
])
|
||||
head.push([
|
||||
"meta",
|
||||
'meta',
|
||||
{
|
||||
name: "twitter:image",
|
||||
content: `${hostname}/${pageData.frontmatter.image.replace(/^\//, "")}`,
|
||||
},
|
||||
]);
|
||||
name: 'twitter:image',
|
||||
content: `${hostname}/${pageData.frontmatter.image.replace(/^\//, '')}`
|
||||
}
|
||||
])
|
||||
} else {
|
||||
const url = pageData.filePath.replace("index.md", "").replace(".md", "");
|
||||
const imageUrl = `${url}/__og_image__/og.png`.replaceAll("//", "/").replace(/^\//, "");
|
||||
const url = pageData.filePath.replace('index.md', '').replace('.md', '')
|
||||
const imageUrl = `${url}/__og_image__/og.png`
|
||||
.replaceAll('//', '/')
|
||||
.replace(/^\//, '')
|
||||
|
||||
head.push(
|
||||
["meta", { property: "og:image", content: `${hostname}/${imageUrl}` }],
|
||||
["meta", { property: "og:image:width", content: "1200" }],
|
||||
["meta", { property: "og:image:height", content: "628" }],
|
||||
["meta", { property: "og:image:type", content: "image/png" }],
|
||||
["meta", { property: "og:image:alt", content: pageData.frontmatter.title }],
|
||||
["meta", { name: "twitter:image", content: `${hostname}/${imageUrl}` }],
|
||||
["meta", { name: "twitter:image:width", content: "1200" }],
|
||||
["meta", { name: "twitter:image:height", content: "628" }],
|
||||
["meta", { name: "twitter:image:alt", content: pageData.frontmatter.title }],
|
||||
);
|
||||
['meta', { property: 'og:image', content: `${hostname}/${imageUrl}` }],
|
||||
['meta', { property: 'og:image:width', content: '1200' }],
|
||||
['meta', { property: 'og:image:height', content: '628' }],
|
||||
['meta', { property: 'og:image:type', content: 'image/png' }],
|
||||
[
|
||||
'meta',
|
||||
{ property: 'og:image:alt', content: pageData.frontmatter.title }
|
||||
],
|
||||
['meta', { name: 'twitter:image', content: `${hostname}/${imageUrl}` }],
|
||||
['meta', { name: 'twitter:image:width', content: '1200' }],
|
||||
['meta', { name: 'twitter:image:height', content: '628' }],
|
||||
[
|
||||
'meta',
|
||||
{ name: 'twitter:image:alt', content: pageData.frontmatter.title }
|
||||
]
|
||||
)
|
||||
}
|
||||
if (pageData.frontmatter.tag) {
|
||||
head.push(["meta", { property: "article:tag", content: pageData.frontmatter.tag }]);
|
||||
head.push([
|
||||
'meta',
|
||||
{ property: 'article:tag', content: pageData.frontmatter.tag }
|
||||
])
|
||||
}
|
||||
if (pageData.frontmatter.date) {
|
||||
head.push([
|
||||
"meta",
|
||||
'meta',
|
||||
{
|
||||
property: "article:published_time",
|
||||
content: pageData.frontmatter.date,
|
||||
},
|
||||
]);
|
||||
property: 'article:published_time',
|
||||
content: pageData.frontmatter.date
|
||||
}
|
||||
])
|
||||
}
|
||||
if (pageData.lastUpdated && pageData.frontmatter.lastUpdated !== false) {
|
||||
head.push([
|
||||
"meta",
|
||||
'meta',
|
||||
{
|
||||
property: "article:modified_time",
|
||||
content: new Date(pageData.lastUpdated).toISOString(),
|
||||
},
|
||||
]);
|
||||
property: 'article:modified_time',
|
||||
content: new Date(pageData.lastUpdated).toISOString()
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
return head;
|
||||
return head
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue