|
|
@ -2,6 +2,7 @@ import path from 'path'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
import { SiteConfig, resolveSiteDataByRoute } from '../config'
|
|
|
|
import { SiteConfig, resolveSiteDataByRoute } from '../config'
|
|
|
|
import { HeadConfig } from '../shared'
|
|
|
|
import { HeadConfig } from '../shared'
|
|
|
|
|
|
|
|
import { processHead } from '../../shared/shared'
|
|
|
|
import { normalizePath, transformWithEsbuild } from 'vite'
|
|
|
|
import { normalizePath, transformWithEsbuild } from 'vite'
|
|
|
|
import { RollupOutput, OutputChunk, OutputAsset } from 'rollup'
|
|
|
|
import { RollupOutput, OutputChunk, OutputAsset } from 'rollup'
|
|
|
|
import { slash } from '../utils/slash'
|
|
|
|
import { slash } from '../utils/slash'
|
|
|
@ -97,11 +98,7 @@ export async function renderPage(
|
|
|
|
? `${pageData.title} | ${siteData.title}`
|
|
|
|
? `${pageData.title} | ${siteData.title}`
|
|
|
|
: siteData.title
|
|
|
|
: siteData.title
|
|
|
|
|
|
|
|
|
|
|
|
const head = addSocialTags(
|
|
|
|
const head = processHead(siteData.head, pageData);
|
|
|
|
title,
|
|
|
|
|
|
|
|
...siteData.head,
|
|
|
|
|
|
|
|
...filterOutHeadDescription(pageData.frontmatter.head)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let inlinedScript = ''
|
|
|
|
let inlinedScript = ''
|
|
|
|
if (config.mpa && result) {
|
|
|
|
if (config.mpa && result) {
|
|
|
@ -133,7 +130,7 @@ export async function renderPage(
|
|
|
|
${stylesheetLink}
|
|
|
|
${stylesheetLink}
|
|
|
|
${preloadLinksString}
|
|
|
|
${preloadLinksString}
|
|
|
|
${prefetchLinkString}
|
|
|
|
${prefetchLinkString}
|
|
|
|
${await renderHead(head)}
|
|
|
|
${await renderHead([...head, ...pageData.head])}
|
|
|
|
</head>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<body>
|
|
|
|
<div id="app">${content}</div>
|
|
|
|
<div id="app">${content}</div>
|
|
|
@ -207,29 +204,3 @@ function renderAttrs(attrs: Record<string, string>): string {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.join('')
|
|
|
|
.join('')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isMetaDescription(headConfig: HeadConfig) {
|
|
|
|
|
|
|
|
const [type, attrs] = headConfig
|
|
|
|
|
|
|
|
return type === 'meta' && attrs?.name === 'description'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function filterOutHeadDescription(head: HeadConfig[] | undefined) {
|
|
|
|
|
|
|
|
return head ? head.filter((h) => !isMetaDescription(h)) : []
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function hasTag(head: HeadConfig[], tag: HeadConfig) {
|
|
|
|
|
|
|
|
const [tagType, tagAttrs] = tag
|
|
|
|
|
|
|
|
const [attr, value] = Object.entries(tagAttrs)[0] // First key
|
|
|
|
|
|
|
|
return head.some(([type, attrs]) => type === tagType && attrs[attr] === value)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addSocialTags(title: string, ...head: HeadConfig[]) {
|
|
|
|
|
|
|
|
const tags: HeadConfig[] = [
|
|
|
|
|
|
|
|
['meta', { name: 'twitter:title', content: title }],
|
|
|
|
|
|
|
|
['meta', { property: 'og:title', content: title }]
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
tags.filter((tagAttrs) => {
|
|
|
|
|
|
|
|
if (!hasTag(head, tagAttrs)) head.push(tagAttrs)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return head
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|