Skip to content

Commit

Permalink
feat: add rich media search
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed May 6, 2024
1 parent e155578 commit 450a989
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
45 changes: 41 additions & 4 deletions helpers/vite-prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from './utils';
import { ArticleMeta } from './vite-route-generator';

import dayjs from 'dayjs';
import { readdirSync, readFileSync } from 'node:fs';
import { loadEnv } from 'vite';
import selfVitePrerender from 'vite-plugin-prerender';
Expand Down Expand Up @@ -56,13 +57,31 @@ function getMetaTag(meta: ArticleMeta | undefined, route: ResolveRouteObject) {
<meta property="article" content="https://yuanyxh.com${route.fullPath}" />
<meta property="article:published_time" content="${meta.date}" />
<meta property="article:author" content="https://yuanyxh.com/profile/about_me.html" />
<meta property="og:image" content="${meta.imageUrl}">
<meta property="og:image" content="${meta.imageUrl || 'https://yuanyxh.com/logo.webp'}">
<meta property="og:description" content="${meta.description}">
<meta property="og:title" content="${env.VITE_APP_TITLE}: ${meta.title}">
<meta name="twitter:title" content="${env.VITE_APP_TITLE}: ${meta.title}">
<meta name="twitter:description" content="${meta.description}">
<meta name="twitter:image" content="${meta.imageUrl || 'https://yuanyxh.com/favicon.ico'}">
<meta name="twitter:image" content="${meta.imageUrl || 'https://yuanyxh.com/logo.webp'}">
<meta name="description" content="${meta.description}">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "${meta.title}",
"image": [
"${meta.imageUrl || 'https://yuanyxh.com/logo.webp'}"
],
"datePublished": "${dayjs(meta.date).toISOString()}",
"author": [{
"@type": "Person",
"name": "yuanyxh",
"url": "https://yuanyxh.com/profile/about_me.html"
}]
}
</script>
<title>${env.VITE_APP_TITLE}: ${meta.title}</title>
`;
} else {
Expand All @@ -73,8 +92,26 @@ function getMetaTag(meta: ArticleMeta | undefined, route: ResolveRouteObject) {
<meta name="description" content="技术博客,演示站,工具站;做一个有用的网站,拥有优秀的用户体验。站在巨人的肩膀上/If I have seen further than others, it is by standing upon the shoulders of giants.">
<meta name="twitter:title" content="${env.VITE_APP_TITLE}">
<meta name="twitter:description" content="技术博客,演示站,工具站;做一个有用的网站,拥有优秀的用户体验。站在巨人的肩膀上/If I have seen further than others, it is by standing upon the shoulders of giants.">
<meta property="og:image" content="https://yuanyxh.com/favicon.ico">
<meta name="twitter:image" content="https://yuanyxh.com/favicon.ico">
<meta property="og:image" content="https://yuanyxh.com/logo.webp">
<meta name="twitter:image" content="https://yuanyxh.com/logo.webp">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "${env.VITE_APP_TITLE}",
"image": [
"https://yuanyxh.com/logo.webp"
],
"dateModified": "${dayjs().toISOString()}",
"author": [{
"@type": "Person",
"name": "yuanyxh",
"url": "https://yuanyxh.com/profile/about_me.html"
}]
}
</script>
<title>${env.VITE_APP_TITLE}</title>
`;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"dayjs": "^1.11.11",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
Expand Down
4 changes: 3 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/logo.webp
Binary file not shown.

0 comments on commit 450a989

Please sign in to comment.