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
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
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const LINT_CONFIG_FILENAME = '.yfmlint';
export const SINGLE_PAGE_FILENAME = 'single-page.html';
export const SINGLE_PAGE_DATA_FILENAME = 'single-page.json';
export const CUSTOM_STYLE = 'custom-style';
export const METADATA_TAG_NAME = 'tagName';

export enum Stage {
NEW = 'new',
Expand Down
13 changes: 10 additions & 3 deletions src/utils/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {join} from 'path';
import {platform} from 'process';
import {flatMapDeep, isArray, isObject, isString} from 'lodash';

import {CUSTOM_STYLE, Platforms, RTL_LANGS} from '../constants';
import {CUSTOM_STYLE, METADATA_TAG_NAME, Platforms, RTL_LANGS} from '../constants';
import {LeadingPage, Resources, SinglePageResult, TextItems, VarsMetadata} from '../models';
import {ArgvService, PluginService} from '../services';
import {preprocessPageHtmlForSinglePage} from './singlePage';
Expand Down Expand Up @@ -109,12 +109,19 @@ function getMetadata(metadata: VarsMetadata | undefined, restMeta: LeadingPage['
let result = '';

const addMetaTagsFromObject = (value: Record<string, string | boolean | TextItems>) => {
const tagName = value[METADATA_TAG_NAME] || 'meta';

const args = Object.entries(value).reduce((acc, [name, content]) => {
return acc + `${escape(name)}="${escape(content.toString())}" `;
return (
acc +
(name === METADATA_TAG_NAME
? ''
: `${escape(name)}="${escape(content.toString())}" `)
);
}, '');

if (args.length) {
result += `<meta ${args} />` + сarriage;
result += `<${tagName} ${args} />` + сarriage;
}
};

Expand Down
Loading