Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): implement i18n meta tag #548

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions apps/docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { packagesLinksGenerator } from './packages';
import { platformLinksGenerator } from './platform';

import { zh } from "./zh/config";

import { metaObject as zhMetaObject } from "./zh/meta";
const { packagesNavItem, packagesSidebar } = packagesLinksGenerator();
const { platformNavItem, platformSidebar } = platformLinksGenerator();

Expand Down Expand Up @@ -145,13 +145,27 @@ export default defineConfig({

const addOg = (prop: string, content: string) => addMeta(`og:${prop}`, content);

addOg('title', isHome ? siteTitle : `${title} | ${siteTitle}`);
addOg('site_name', 'Telegram Mini Apps Platform Documentation');
addOg('image', `${siteBase}thumbnail-1200x630.6b8f54aa217a6baed4703ad5af866677.png`);
addOg('image:width', '1200');
addOg('image:height', '630');
addOg('image:type', 'image/png');
addOg('locale', lang.replace(/-/, '_'));
const i18nMeta = {
zh: zhMetaObject,
};

let baseMeta = {
site_name: 'Telegram Mini Apps Platform Documentation',
image: `${siteBase}thumbnail-1200x630.6b8f54aa217a6baed4703ad5af866677.png`,
'image:width': '1200',
'image:height': '630',
'image:type': 'image/png',
locale: lang.replace(/-/, '_'),
// for i18n
'locale:alternate': 'zh_CN',
};

const currentI18nMeta = Object.entries(i18nMeta).find(([key, _]) => filePath?.startsWith(`${key}/`))?.[1];

const i18nSiteTitle = currentI18nMeta?.title ?? siteTitle;
baseMeta = { ...baseMeta, ...currentI18nMeta, title: isHome ? i18nSiteTitle : `${title} | ${i18nSiteTitle}` } as typeof baseMeta;

Object.entries(baseMeta).forEach(([key, value]) => addOg(key, value));

// To make it correctly display in Telegram.
addMeta('twitter:card', 'summary_large_image');
Expand Down
5 changes: 5 additions & 0 deletions apps/docs/.vitepress/zh/meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const metaObject = {
site_name: "Telegram 小程序平台文档",
title: "Telegram 小程序"
};

Loading