mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-01 02:41:39 -05:00
✨ Added custom fonts (#21564)
ref DES-949 This adds custom fonts feature allowing users to select heading and body fonts for their themes from a curated list. This allows publishers to have more control over their brand, and allows themes to have a wider range of styles to appeal to different audiences. Without custom fonts support, themes will continue to work as normal, but users won't be able to customize their typography. As for the official themes, all of them will support custom fonts. --------- Co-authored-by: Aileen Booker <AileenCGN@gmail.com>
This commit is contained in:
parent
b55ac9a03a
commit
177e604501
11 changed files with 96 additions and 138 deletions
|
@ -63,10 +63,6 @@ const features = [{
|
|||
title: 'Staff 2FA',
|
||||
description: 'Enables email verification for staff logins',
|
||||
flag: 'staff2fa'
|
||||
}, {
|
||||
title: 'Custom Fonts',
|
||||
description: 'Enables new custom font settings',
|
||||
flag: 'customFonts'
|
||||
}];
|
||||
|
||||
const AlphaFeatures: React.FC = () => {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import BehindFeatureFlag from '../../../BehindFeatureFlag';
|
||||
import React, {useState} from 'react';
|
||||
import UnsplashSelector from '../../../selectors/UnsplashSelector';
|
||||
import clsx from 'clsx';
|
||||
|
@ -319,52 +318,50 @@ const GlobalSettings: React.FC<{ values: GlobalSettingValues, updateSetting: (ke
|
|||
}
|
||||
</div>
|
||||
</Form>
|
||||
<BehindFeatureFlag flag="customFonts">
|
||||
<Form className='-mt-4' gap='sm' margins='lg' title='Typography'>
|
||||
<Select
|
||||
className={selectFont(selectedHeadingFont.label, true)}
|
||||
components={{Option, SingleValue}}
|
||||
controlClasses={{control: '!min-h-16 !pl-2', option: '!pl-2'}}
|
||||
hint={''}
|
||||
menuShouldScrollIntoView={true}
|
||||
options={customHeadingFonts}
|
||||
selectedOption={selectedHeadingFont}
|
||||
testId='heading-font-select'
|
||||
title={'Heading font'}
|
||||
onSelect={(option) => {
|
||||
if (option?.value === DEFAULT_FONT) {
|
||||
setHeadingFont({name: DEFAULT_FONT, creator: themeNameVersion});
|
||||
updateSetting('heading_font', '');
|
||||
} else {
|
||||
setHeadingFont({name: option?.value || '', creator: CUSTOM_FONTS.heading.find(f => f.name === option?.value)?.creator || ''});
|
||||
updateSetting('heading_font', option?.value || '');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Select
|
||||
className={selectFont(selectedBodyFont.label, false)}
|
||||
components={{Option, SingleValue}}
|
||||
controlClasses={{control: '!min-h-16 !pl-2', option: '!pl-2'}}
|
||||
hint={''}
|
||||
maxMenuHeight={200}
|
||||
menuPosition='fixed'
|
||||
menuShouldScrollIntoView={true}
|
||||
options={customBodyFonts}
|
||||
selectedOption={selectedBodyFont}
|
||||
testId='body-font-select'
|
||||
title={'Body font'}
|
||||
onSelect={(option) => {
|
||||
if (option?.value === DEFAULT_FONT) {
|
||||
setBodyFont({name: DEFAULT_FONT, creator: themeNameVersion});
|
||||
updateSetting('body_font', '');
|
||||
} else {
|
||||
setBodyFont({name: option?.value || '', creator: CUSTOM_FONTS.body.find(f => f.name === option?.value)?.creator || ''});
|
||||
updateSetting('body_font', option?.value || '');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Form>
|
||||
</BehindFeatureFlag>
|
||||
<Form className='-mt-4' gap='sm' margins='lg' title='Typography'>
|
||||
<Select
|
||||
className={selectFont(selectedHeadingFont.label, true)}
|
||||
components={{Option, SingleValue}}
|
||||
controlClasses={{control: '!min-h-16 !pl-2', option: '!pl-2'}}
|
||||
hint={''}
|
||||
menuShouldScrollIntoView={true}
|
||||
options={customHeadingFonts}
|
||||
selectedOption={selectedHeadingFont}
|
||||
testId='heading-font-select'
|
||||
title={'Heading font'}
|
||||
onSelect={(option) => {
|
||||
if (option?.value === DEFAULT_FONT) {
|
||||
setHeadingFont({name: DEFAULT_FONT, creator: themeNameVersion});
|
||||
updateSetting('heading_font', '');
|
||||
} else {
|
||||
setHeadingFont({name: option?.value || '', creator: CUSTOM_FONTS.heading.find(f => f.name === option?.value)?.creator || ''});
|
||||
updateSetting('heading_font', option?.value || '');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Select
|
||||
className={selectFont(selectedBodyFont.label, false)}
|
||||
components={{Option, SingleValue}}
|
||||
controlClasses={{control: '!min-h-16 !pl-2', option: '!pl-2'}}
|
||||
hint={''}
|
||||
maxMenuHeight={200}
|
||||
menuPosition='fixed'
|
||||
menuShouldScrollIntoView={true}
|
||||
options={customBodyFonts}
|
||||
selectedOption={selectedBodyFont}
|
||||
testId='body-font-select'
|
||||
title={'Body font'}
|
||||
onSelect={(option) => {
|
||||
if (option?.value === DEFAULT_FONT) {
|
||||
setBodyFont({name: DEFAULT_FONT, creator: themeNameVersion});
|
||||
updateSetting('body_font', '');
|
||||
} else {
|
||||
setBodyFont({name: option?.value || '', creator: CUSTOM_FONTS.body.find(f => f.name === option?.value)?.creator || ''});
|
||||
updateSetting('body_font', option?.value || '');
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import React from 'react';
|
||||
import ThemeSetting from './ThemeSetting';
|
||||
import useFeatureFlag from '../../../../hooks/useFeatureFlag';
|
||||
import {CustomThemeSetting} from '@tryghost/admin-x-framework/api/customThemeSettings';
|
||||
import {Form} from '@tryghost/admin-x-design-system';
|
||||
import {Theme, useBrowseThemes} from '@tryghost/admin-x-framework/api/themes';
|
||||
|
@ -44,7 +43,6 @@ const ThemeSettings: React.FC<ThemeSettingsProps> = ({sections, updateSetting})
|
|||
const {data: themesData} = useBrowseThemes();
|
||||
const activeTheme = themesData?.themes.find((theme: Theme) => theme.active);
|
||||
const activeThemeName = activeTheme?.package.name?.toLowerCase() || '';
|
||||
const hasCustomFonts = useFeatureFlag('customFonts');
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -67,11 +65,9 @@ const ThemeSettings: React.FC<ThemeSettingsProps> = ({sections, updateSetting})
|
|||
|
||||
// hides typography related theme settings from official themes
|
||||
// should be removed once we remove the settings from the themes in 6.0
|
||||
if (hasCustomFonts) {
|
||||
const hidingSettings = themeSettingsMap[activeThemeName];
|
||||
if (hidingSettings && hidingSettings.includes(setting.key)) {
|
||||
spaceClass += ' hidden';
|
||||
}
|
||||
const hidingSettings = themeSettingsMap[activeThemeName];
|
||||
if (hidingSettings && hidingSettings.includes(setting.key)) {
|
||||
spaceClass += ' hidden';
|
||||
}
|
||||
|
||||
previousType = setting.type;
|
||||
|
|
|
@ -3,7 +3,6 @@ import {
|
|||
mockApi,
|
||||
mockSitePreview,
|
||||
responseFixtures,
|
||||
toggleLabsFlag,
|
||||
updatedSettingsResponse
|
||||
} from '@tryghost/admin-x-framework/test/acceptance';
|
||||
import {expect, test} from '@playwright/test';
|
||||
|
@ -306,7 +305,6 @@ test.describe('Design settings', async () => {
|
|||
});
|
||||
|
||||
test('Custom fonts', async ({page}) => {
|
||||
toggleLabsFlag('customFonts', true);
|
||||
await mockApi({page, requests: {
|
||||
...globalDataRequests,
|
||||
browseCustomThemeSettings: {method: 'GET', path: '/custom_theme_settings/', response: {
|
||||
|
@ -352,7 +350,6 @@ test.describe('Design settings', async () => {
|
|||
});
|
||||
|
||||
test('Custom fonts setting back to default', async ({page}) => {
|
||||
toggleLabsFlag('customFonts', true);
|
||||
await mockApi({page, requests: {
|
||||
...globalDataRequests,
|
||||
browseSettings: {...globalDataRequests.browseSettings, response: updatedSettingsResponse([
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Usage: `{{body_class}}`
|
||||
//
|
||||
// Output classes for the body element
|
||||
const {labs, settingsCache} = require('../services/proxy');
|
||||
const {settingsCache} = require('../services/proxy');
|
||||
const {generateCustomFontBodyClass, isValidCustomFont, isValidCustomHeadingFont} = require('@tryghost/custom-fonts');
|
||||
const {SafeString} = require('../services/handlebars');
|
||||
|
||||
|
@ -45,30 +45,28 @@ module.exports = function body_class(options) { // eslint-disable-line camelcase
|
|||
classes.push('paged');
|
||||
}
|
||||
|
||||
if (labs.isSet('customFonts')) {
|
||||
// Check if if the request is for a site preview, in which case we **always** use the custom font values
|
||||
// from the passed in data, even when they're empty strings or settings cache has values.
|
||||
const isSitePreview = options.data.site._preview;
|
||||
// Taking the fonts straight from the passed in data, as they can't be used from the
|
||||
// settings cache for the theme preview until the settings are saved. Once saved,
|
||||
// we need to use the settings cache to provide the correct CSS injection.
|
||||
const headingFont = isSitePreview ? options.data.site.heading_font : settingsCache.get('heading_font');
|
||||
const bodyFont = isSitePreview ? options.data.site.body_font : settingsCache.get('body_font');
|
||||
// Check if if the request is for a site preview, in which case we **always** use the custom font values
|
||||
// from the passed in data, even when they're empty strings or settings cache has values.
|
||||
const isSitePreview = options.data?.site?._preview ?? false;
|
||||
// Taking the fonts straight from the passed in data, as they can't be used from the
|
||||
// settings cache for the theme preview until the settings are saved. Once saved,
|
||||
// we need to use the settings cache to provide the correct CSS injection.
|
||||
const headingFont = isSitePreview ? options.data?.site?.heading_font : settingsCache.get('heading_font');
|
||||
const bodyFont = isSitePreview ? options.data?.site?.body_font : settingsCache.get('body_font');
|
||||
|
||||
if ((typeof headingFont === 'string' && isValidCustomHeadingFont(headingFont)) ||
|
||||
(typeof bodyFont === 'string' && isValidCustomFont(bodyFont))) {
|
||||
/** @type FontSelection */
|
||||
const fontSelection = {};
|
||||
if ((typeof headingFont === 'string' && isValidCustomHeadingFont(headingFont)) ||
|
||||
(typeof bodyFont === 'string' && isValidCustomFont(bodyFont))) {
|
||||
/** @type FontSelection */
|
||||
const fontSelection = {};
|
||||
|
||||
if (headingFont) {
|
||||
fontSelection.heading = headingFont;
|
||||
}
|
||||
if (bodyFont) {
|
||||
fontSelection.body = bodyFont;
|
||||
}
|
||||
const customBodyClasses = generateCustomFontBodyClass(fontSelection);
|
||||
classes.push(new SafeString(customBodyClasses));
|
||||
if (headingFont) {
|
||||
fontSelection.heading = headingFont;
|
||||
}
|
||||
if (bodyFont) {
|
||||
fontSelection.body = bodyFont;
|
||||
}
|
||||
const customBodyClasses = generateCustomFontBodyClass(fontSelection);
|
||||
classes.push(new SafeString(customBodyClasses));
|
||||
}
|
||||
|
||||
classes = classes.join(' ').trim();
|
||||
|
|
|
@ -353,29 +353,27 @@ module.exports = async function ghost_head(options) { // eslint-disable-line cam
|
|||
head.push(getTinybirdTrackerScript(dataRoot));
|
||||
}
|
||||
|
||||
if (labs.isSet('customFonts')) {
|
||||
// Check if if the request is for a site preview, in which case we **always** use the custom font values
|
||||
// from the passed in data, even when they're empty strings or settings cache has values.
|
||||
const isSitePreview = options.data.site._preview;
|
||||
// Taking the fonts straight from the passed in data, as they can't be used from the
|
||||
// settings cache for the theme preview until the settings are saved. Once saved,
|
||||
// we need to use the settings cache to provide the correct CSS injection.
|
||||
const headingFont = isSitePreview ? options.data.site.heading_font : settingsCache.get('heading_font');
|
||||
const bodyFont = isSitePreview ? options.data.site.body_font : settingsCache.get('body_font');
|
||||
if ((typeof headingFont === 'string' && isValidCustomHeadingFont(headingFont)) ||
|
||||
(typeof bodyFont === 'string' && isValidCustomFont(bodyFont))) {
|
||||
/** @type FontSelection */
|
||||
const fontSelection = {};
|
||||
// Check if if the request is for a site preview, in which case we **always** use the custom font values
|
||||
// from the passed in data, even when they're empty strings or settings cache has values.
|
||||
const isSitePreview = options.data?.site?._preview ?? false;
|
||||
// Taking the fonts straight from the passed in data, as they can't be used from the
|
||||
// settings cache for the theme preview until the settings are saved. Once saved,
|
||||
// we need to use the settings cache to provide the correct CSS injection.
|
||||
const headingFont = isSitePreview ? options.data?.site?.heading_font : settingsCache.get('heading_font');
|
||||
const bodyFont = isSitePreview ? options.data?.site?.body_font : settingsCache.get('body_font');
|
||||
if ((typeof headingFont === 'string' && isValidCustomHeadingFont(headingFont)) ||
|
||||
(typeof bodyFont === 'string' && isValidCustomFont(bodyFont))) {
|
||||
/** @type FontSelection */
|
||||
const fontSelection = {};
|
||||
|
||||
if (headingFont) {
|
||||
fontSelection.heading = headingFont;
|
||||
}
|
||||
if (bodyFont) {
|
||||
fontSelection.body = bodyFont;
|
||||
}
|
||||
const customCSS = generateCustomFontCss(fontSelection);
|
||||
head.push(new SafeString(customCSS));
|
||||
if (headingFont) {
|
||||
fontSelection.heading = headingFont;
|
||||
}
|
||||
if (bodyFont) {
|
||||
fontSelection.body = bodyFont;
|
||||
}
|
||||
const customCSS = generateCustomFontCss(fontSelection);
|
||||
head.push(new SafeString(customCSS));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,8 +46,7 @@ const ALPHA_FEATURES = [
|
|||
'adminXDemo',
|
||||
'contentVisibility',
|
||||
'commentImprovements',
|
||||
'staff2fa',
|
||||
'customFonts'
|
||||
'staff2fa'
|
||||
];
|
||||
|
||||
module.exports.GA_KEYS = [...GA_FEATURES];
|
||||
|
|
|
@ -20,7 +20,6 @@ Object {
|
|||
"collectionsCard": true,
|
||||
"commentImprovements": true,
|
||||
"contentVisibility": true,
|
||||
"customFonts": true,
|
||||
"editorExcerpt": true,
|
||||
"emailCustomization": true,
|
||||
"i18n": true,
|
||||
|
|
|
@ -1032,7 +1032,7 @@ Object {
|
|||
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
|
||||
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
|
||||
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" crossorigin=\\"anonymous\\"></script>
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
|
||||
}
|
||||
|
@ -1106,7 +1106,7 @@ Object {
|
|||
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
|
||||
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
|
||||
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" crossorigin=\\"anonymous\\"></script>
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
|
||||
}
|
||||
|
@ -1180,7 +1180,7 @@ Object {
|
|||
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
|
||||
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
|
||||
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" crossorigin=\\"anonymous\\"></script>
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
|
||||
}
|
||||
|
@ -1254,7 +1254,7 @@ Object {
|
|||
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
|
||||
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
|
||||
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" crossorigin=\\"anonymous\\"></script>
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
|
||||
}
|
||||
|
@ -1403,7 +1403,7 @@ Object {
|
|||
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
|
||||
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
|
||||
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" crossorigin=\\"anonymous\\"></script>
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">
|
||||
<link rel=\\"preconnect\\" href=\\"https://fonts.bunny.net\\"><link rel=\\"stylesheet\\" href=\\"https://fonts.bunny.net/css?family=space-grotesk:700|poppins:400,500,600\\"><style>:root {--gh-font-heading: Space Grotesk;--gh-font-body: Poppins;}</style>",
|
||||
|
@ -1553,7 +1553,7 @@ Object {
|
|||
<meta name=\\"generator\\" content=\\"Ghost 0.3\\">
|
||||
<link rel=\\"alternate\\" type=\\"application/rss+xml\\" title=\\"Ghost\\" href=\\"http://localhost:65530/rss/\\">
|
||||
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" crossorigin=\\"anonymous\\"></script>
|
||||
<script defer src=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/sodo-search.min.js\\" data-key=\\"xyz\\" data-styles=\\"https://cdn.jsdelivr.net/ghost/sodo-search@~[[VERSION]]/umd/main.css\\" data-sodo-search=\\"http://127.0.0.1:2369/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">
|
||||
<link rel=\\"preconnect\\" href=\\"https://fonts.bunny.net\\"><link rel=\\"stylesheet\\" href=\\"https://fonts.bunny.net/css?family=undefined|lora:400,700\\"><style>:root {--gh-font-heading: Playfair Display;--gh-font-body: Lora;}</style>",
|
||||
|
|
|
@ -7,7 +7,7 @@ const body_class = require('../../../../core/frontend/helpers/body_class');
|
|||
|
||||
// Stubs
|
||||
const proxy = require('../../../../core/frontend/services/proxy');
|
||||
const {settingsCache, labs} = proxy;
|
||||
const {settingsCache} = proxy;
|
||||
|
||||
describe('{{body_class}} helper', function () {
|
||||
let options = {};
|
||||
|
@ -30,7 +30,8 @@ describe('{{body_class}} helper', function () {
|
|||
root: {
|
||||
context: [],
|
||||
settings: {active_theme: 'casper'}
|
||||
}
|
||||
},
|
||||
site: {}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -163,7 +164,6 @@ describe('{{body_class}} helper', function () {
|
|||
|
||||
describe('custom fonts', function () {
|
||||
let settingsCacheStub;
|
||||
let labsStub;
|
||||
|
||||
function callBodyClassWithContext(context, self) {
|
||||
options.data.root.context = context;
|
||||
|
@ -174,7 +174,6 @@ describe('{{body_class}} helper', function () {
|
|||
}
|
||||
|
||||
beforeEach(function () {
|
||||
labsStub = sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||
settingsCacheStub = sinon.stub(settingsCache, 'get');
|
||||
options = {
|
||||
data: {
|
||||
|
@ -216,17 +215,6 @@ describe('{{body_class}} helper', function () {
|
|||
rendered.string.should.equal('post-template tag-foo tag-bar gh-font-heading-space-grotesk gh-font-body-noto-sans');
|
||||
});
|
||||
|
||||
it('does not include custom font classes when custom fonts are not enabled', function () {
|
||||
labsStub.withArgs('customFonts').returns(false);
|
||||
|
||||
const rendered = callBodyClassWithContext(
|
||||
['post'],
|
||||
{relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}
|
||||
);
|
||||
|
||||
rendered.string.should.equal('post-template tag-foo tag-bar');
|
||||
});
|
||||
|
||||
it('includes custom font classes for home page when set in options data object', function () {
|
||||
options.data.site.heading_font = 'Space Grotesk';
|
||||
options.data.site.body_font = '';
|
||||
|
|
|
@ -1128,8 +1128,6 @@ describe('{{ghost_head}} helper', function () {
|
|||
|
||||
describe('custom fonts', function () {
|
||||
it('includes custom font when set in options data object and preview is set', async function () {
|
||||
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||
|
||||
const renderObject = {
|
||||
post: posts[1]
|
||||
};
|
||||
|
@ -1154,7 +1152,6 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
it('includes custom font when set in settings cache and no preview', async function () {
|
||||
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||
settingsCache.get.withArgs('heading_font').returns('Playfair Display');
|
||||
settingsCache.get.withArgs('body_font').returns('Lora');
|
||||
|
||||
|
@ -1174,8 +1171,6 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
it('does not include custom font when not set', async function () {
|
||||
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||
|
||||
settingsCache.get.withArgs('heading_font').returns(null);
|
||||
settingsCache.get.withArgs('body_font').returns('');
|
||||
|
||||
|
@ -1195,8 +1190,6 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
it('does not include custom font when invalid', async function () {
|
||||
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||
|
||||
settingsCache.get.withArgs('heading_font').returns(null);
|
||||
settingsCache.get.withArgs('body_font').returns('Wendy Sans');
|
||||
|
||||
|
@ -1223,7 +1216,6 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
it('does not inject custom fonts when preview is set and default font was selected (empty string)', async function () {
|
||||
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||
// The site has fonts set up, but we override them with Theme default fonts (empty string)
|
||||
settingsCache.get.withArgs('heading_font').returns('Playfair Display');
|
||||
settingsCache.get.withArgs('body_font').returns('Lora');
|
||||
|
@ -1248,8 +1240,6 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
it('can handle preview being set and custom font keys missing', async function () {
|
||||
sinon.stub(labs, 'isSet').withArgs('customFonts').returns(true);
|
||||
|
||||
// The site has fonts set up, but we override them with Theme default fonts (empty string)
|
||||
settingsCache.get.withArgs('heading_font').returns('Playfair Display');
|
||||
settingsCache.get.withArgs('body_font').returns('Lora');
|
||||
|
|
Loading…
Add table
Reference in a new issue