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: add meta for toc in head link #710

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
19 changes: 18 additions & 1 deletion src/utils/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ export type Meta = TitleMeta &
metadata: VarsMetadata;
};

function generateTags(tag: string, data: VarsMetadata[]) {
return (
data?.map((meta: VarsMetadata) => {
const values = Object.entries(meta).map(
([key, value]: [string, unknown]) =>
`${key.replace(/[\s"]/g, '"')}="${String(value).replace(/"/g, '"')}"`,
);
return `<${tag} ${values.join(' ')}>`;
}) || []
);
}

export function generateStaticMarkup(
props: DocInnerProps<DocPageData>,
pathToBundle: string,
): string {
const {style, script, metadata, ...restYamlConfigMeta} = (props.data.meta as Meta) || {};
const {title: tocTitle} = props.data.toc;
const {title: tocTitle, head: tocHead} = props.data.toc;
const {title: pageTitle} = props.data;

const title = getTitle({
Expand All @@ -46,13 +58,18 @@ export function generateStaticMarkup(
const html = staticContent ? render(props) : '';
const isRTL = RTL_LANGS.includes(props.lang);

const headMeta = generateTags('meta', tocHead?.meta);
const headLink = generateTags('link', tocHead?.link);

return `
<!DOCTYPE html>
<html lang="${props.lang}" dir="${isRTL ? 'rtl' : 'ltr'}">
<head>
<meta charset="utf-8">
${getMetadata(metadata, restYamlConfigMeta)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А вот это не дублирует headMeta чуть ниже?

Copy link
Contributor Author

@makamekm makamekm Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Там только <script /> и <link rel="stylesheet" type="text/css" />.
Те такой вариант дает менять стили в более гибком варианте. Хотя цель этого не дать добавлять стили, а дать добавить og теги и другие теги для треков и интеграций с непостоянным наполнением ([name]="value').

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переделал решение под то что уже есть. Таким образом добавил опциональное поле tagName для возможности проставить <${tagName} {...args} />

<meta name="viewport" content="width=device-width, initial-scale=1.0">
${headMeta.join('\n')}
${headLink.join('\n')}
<title>${title}</title>
<style type="text/css">
body {
Expand Down
Loading