mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Fixed theme preview not working when reverting the default theme fonts
closes DES-887 - We were using an incorrect logic to determine if we need to grab the custom fonts from the data object or the settings cache when rendering `ghost_head` and `body_class` - Instead of falling back to the settings cache if there's no font passed in the data object, we first need to check if we're in a preview context - When knowing that we're in a preview context, we force the helpers to use the values from the passed in data object, even when those values are empty. This is the case when the custom font selected is 'Theme default'.
This commit is contained in:
parent
69cc1bf866
commit
45c1be0c98
5 changed files with 396 additions and 8 deletions
|
@ -46,11 +46,14 @@ module.exports = function body_class(options) { // eslint-disable-line camelcase
|
|||
}
|
||||
|
||||
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 = options.data.site.heading_font || settingsCache.get('heading_font');
|
||||
const bodyFont = options.data.site.body_font || settingsCache.get('body_font');
|
||||
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))) {
|
||||
|
|
|
@ -345,11 +345,14 @@ module.exports = async function ghost_head(options) { // eslint-disable-line cam
|
|||
}
|
||||
|
||||
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 = options.data.site.heading_font || settingsCache.get('heading_font');
|
||||
const bodyFont = options.data.site.body_font || settingsCache.get('body_font');
|
||||
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 */
|
||||
|
|
|
@ -959,6 +959,80 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper custom fonts can handle preview being set and custom font keys missing 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
|
||||
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
|
||||
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
|
||||
|
||||
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
|
||||
<meta property=\\"og:type\\" content=\\"article\\">
|
||||
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
|
||||
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
|
||||
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
|
||||
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
|
||||
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
|
||||
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
|
||||
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
|
||||
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
|
||||
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
|
||||
<meta name=\\"twitter:data1\\" content=\\"name\\">
|
||||
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
|
||||
|
||||
<script type=\\"application/ld+json\\">
|
||||
{
|
||||
\\"@context\\": \\"https://schema.org\\",
|
||||
\\"@type\\": \\"Article\\",
|
||||
\\"publisher\\": {
|
||||
\\"@type\\": \\"Organization\\",
|
||||
\\"name\\": \\"Ghost\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/\\",
|
||||
\\"logo\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
|
||||
}
|
||||
},
|
||||
\\"author\\": {
|
||||
\\"@type\\": \\"Person\\",
|
||||
\\"name\\": \\"name\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
|
||||
},
|
||||
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
|
||||
\\"sameAs\\": [
|
||||
\\"http://authorwebsite.com\\",
|
||||
\\"https://www.facebook.com/testuser\\",
|
||||
\\"https://twitter.com/testuser\\"
|
||||
]
|
||||
},
|
||||
\\"headline\\": \\"About\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
|
||||
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
|
||||
},
|
||||
\\"description\\": \\"all about our site\\",
|
||||
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
|
||||
}
|
||||
</script>
|
||||
|
||||
<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/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper custom fonts does not include custom font when invalid 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
|
||||
|
@ -1107,6 +1181,80 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper custom fonts does not inject custom fonts when preview is set and default font was selected (empty string) 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
|
||||
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
|
||||
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
|
||||
|
||||
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
|
||||
<meta property=\\"og:type\\" content=\\"article\\">
|
||||
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
|
||||
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
|
||||
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
|
||||
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
|
||||
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
|
||||
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
|
||||
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
|
||||
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
|
||||
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
|
||||
<meta name=\\"twitter:data1\\" content=\\"name\\">
|
||||
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
|
||||
|
||||
<script type=\\"application/ld+json\\">
|
||||
{
|
||||
\\"@context\\": \\"https://schema.org\\",
|
||||
\\"@type\\": \\"Article\\",
|
||||
\\"publisher\\": {
|
||||
\\"@type\\": \\"Organization\\",
|
||||
\\"name\\": \\"Ghost\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/\\",
|
||||
\\"logo\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
|
||||
}
|
||||
},
|
||||
\\"author\\": {
|
||||
\\"@type\\": \\"Person\\",
|
||||
\\"name\\": \\"name\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
|
||||
},
|
||||
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
|
||||
\\"sameAs\\": [
|
||||
\\"http://authorwebsite.com\\",
|
||||
\\"https://www.facebook.com/testuser\\",
|
||||
\\"https://twitter.com/testuser\\"
|
||||
]
|
||||
},
|
||||
\\"headline\\": \\"About\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
|
||||
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
|
||||
},
|
||||
\\"description\\": \\"all about our site\\",
|
||||
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
|
||||
}
|
||||
</script>
|
||||
|
||||
<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/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper custom fonts includes custom font when set in options data object 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
|
||||
|
@ -1182,6 +1330,81 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper custom fonts includes custom font when set in options data object and preview is set 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
|
||||
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
|
||||
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
|
||||
|
||||
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
|
||||
<meta property=\\"og:type\\" content=\\"article\\">
|
||||
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
|
||||
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
|
||||
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
|
||||
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
|
||||
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
|
||||
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
|
||||
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
|
||||
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
|
||||
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
|
||||
<meta name=\\"twitter:data1\\" content=\\"name\\">
|
||||
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
|
||||
|
||||
<script type=\\"application/ld+json\\">
|
||||
{
|
||||
\\"@context\\": \\"https://schema.org\\",
|
||||
\\"@type\\": \\"Article\\",
|
||||
\\"publisher\\": {
|
||||
\\"@type\\": \\"Organization\\",
|
||||
\\"name\\": \\"Ghost\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/\\",
|
||||
\\"logo\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
|
||||
}
|
||||
},
|
||||
\\"author\\": {
|
||||
\\"@type\\": \\"Person\\",
|
||||
\\"name\\": \\"name\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
|
||||
},
|
||||
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
|
||||
\\"sameAs\\": [
|
||||
\\"http://authorwebsite.com\\",
|
||||
\\"https://www.facebook.com/testuser\\",
|
||||
\\"https://twitter.com/testuser\\"
|
||||
]
|
||||
},
|
||||
\\"headline\\": \\"About\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
|
||||
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
|
||||
},
|
||||
\\"description\\": \\"all about our site\\",
|
||||
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
|
||||
}
|
||||
</script>
|
||||
|
||||
<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/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">
|
||||
<style>@import url(https://fonts.bunny.net/css?family=space-grotesk:700);@import url(https://fonts.bunny.net/css?family=poppins:400,500,600);:root {--gh-font-heading: Space Grotesk;--gh-font-body: Poppins;}</style>",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper custom fonts includes custom font when set in settings cache 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
|
||||
|
@ -1257,6 +1480,81 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper custom fonts includes custom font when set in settings cache and no preview 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<meta name=\\"description\\" content=\\"all about our site\\">
|
||||
<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"referrer\\" content=\\"no-referrer-when-downgrade\\">
|
||||
<link rel=\\"amphtml\\" href=\\"http://127.0.0.1:2369/post/amp/\\">
|
||||
|
||||
<meta property=\\"og:site_name\\" content=\\"Ghost\\">
|
||||
<meta property=\\"og:type\\" content=\\"article\\">
|
||||
<meta property=\\"og:title\\" content=\\"Custom Facebook title\\">
|
||||
<meta property=\\"og:description\\" content=\\"Custom Facebook description\\">
|
||||
<meta property=\\"og:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta property=\\"og:image\\" content=\\"http://127.0.0.1:2369/content/images/test-og-image.png\\">
|
||||
<meta property=\\"article:published_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:modified_time\\" content=\\"1970-01-01T00:00:00.000Z\\">
|
||||
<meta property=\\"article:author\\" content=\\"https://www.facebook.com/testuser\\">
|
||||
<meta name=\\"twitter:card\\" content=\\"summary_large_image\\">
|
||||
<meta name=\\"twitter:title\\" content=\\"Custom Twitter title\\">
|
||||
<meta name=\\"twitter:description\\" content=\\"Custom Twitter description\\">
|
||||
<meta name=\\"twitter:url\\" content=\\"http://127.0.0.1:2369/post/\\">
|
||||
<meta name=\\"twitter:image\\" content=\\"http://127.0.0.1:2369/content/images/test-twitter-image.png\\">
|
||||
<meta name=\\"twitter:label1\\" content=\\"Written by\\">
|
||||
<meta name=\\"twitter:data1\\" content=\\"name\\">
|
||||
<meta name=\\"twitter:creator\\" content=\\"@testuser\\">
|
||||
|
||||
<script type=\\"application/ld+json\\">
|
||||
{
|
||||
\\"@context\\": \\"https://schema.org\\",
|
||||
\\"@type\\": \\"Article\\",
|
||||
\\"publisher\\": {
|
||||
\\"@type\\": \\"Organization\\",
|
||||
\\"name\\": \\"Ghost\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/\\",
|
||||
\\"logo\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/favicon.ico\\"
|
||||
}
|
||||
},
|
||||
\\"author\\": {
|
||||
\\"@type\\": \\"Person\\",
|
||||
\\"name\\": \\"name\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-author-image.png\\"
|
||||
},
|
||||
\\"url\\": \\"https://mysite.com/fakeauthor/\\",
|
||||
\\"sameAs\\": [
|
||||
\\"http://authorwebsite.com\\",
|
||||
\\"https://www.facebook.com/testuser\\",
|
||||
\\"https://twitter.com/testuser\\"
|
||||
]
|
||||
},
|
||||
\\"headline\\": \\"About\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/post/\\",
|
||||
\\"datePublished\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"dateModified\\": \\"1970-01-01T00:00:00.000Z\\",
|
||||
\\"image\\": {
|
||||
\\"@type\\": \\"ImageObject\\",
|
||||
\\"url\\": \\"http://127.0.0.1:2369/content/images/test-image-about.png\\"
|
||||
},
|
||||
\\"description\\": \\"all about our site\\",
|
||||
\\"mainEntityOfPage\\": \\"http://127.0.0.1:2369/post/\\"
|
||||
}
|
||||
</script>
|
||||
|
||||
<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/\\" data-locale=\\"en\\" crossorigin=\\"anonymous\\"></script>
|
||||
|
||||
<link href=\\"http://127.0.0.1:2369/webmentions/receive/\\" rel=\\"webmention\\">
|
||||
<style>undefined;@import url(https://fonts.bunny.net/css?family=lora:400,700);:root {--gh-font-heading: Playfair Display;--gh-font-body: Lora;}</style>",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`{{ghost_head}} helper includes tinybird tracker script when config is set Sets tb_post_uuid on post page 1 1`] = `
|
||||
Object {
|
||||
"rendered": "<link rel=\\"canonical\\" href=\\"http://127.0.0.1:2369/post/\\">
|
||||
|
|
|
@ -194,6 +194,7 @@ describe('{{body_class}} helper', function () {
|
|||
it('includes custom font for post when set in options data object', function () {
|
||||
options.data.site.heading_font = 'Space Grotesk';
|
||||
options.data.site.body_font = 'Noto Sans';
|
||||
options.data.site._preview = 'test';
|
||||
|
||||
const rendered = callBodyClassWithContext(
|
||||
['post'],
|
||||
|
@ -203,7 +204,7 @@ 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('includes custom font for post when set in settings cache', function () {
|
||||
it('includes custom font for post when set in settings cache and no preview', function () {
|
||||
settingsCacheStub.withArgs('heading_font').returns('Space Grotesk');
|
||||
settingsCacheStub.withArgs('body_font').returns('Noto Sans');
|
||||
|
||||
|
@ -229,6 +230,7 @@ describe('{{body_class}} helper', function () {
|
|||
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 = '';
|
||||
options.data.site._preview = 'test';
|
||||
|
||||
const rendered = callBodyClassWithContext(
|
||||
['home'],
|
||||
|
@ -237,5 +239,36 @@ describe('{{body_class}} helper', function () {
|
|||
|
||||
rendered.string.should.equal('home-template gh-font-heading-space-grotesk');
|
||||
});
|
||||
|
||||
it('does not inject custom fonts when preview is set and default font was selected (empty string)', function () {
|
||||
// The site has fonts set up, but we override them with Theme default fonts (empty string)
|
||||
settingsCacheStub.withArgs('heading_font').returns('Space Grotesk');
|
||||
settingsCacheStub.withArgs('body_font').returns('Noto Sans');
|
||||
|
||||
options.data.site.heading_font = '';
|
||||
options.data.site.body_font = '';
|
||||
options.data.site._preview = 'test';
|
||||
|
||||
const rendered = callBodyClassWithContext(
|
||||
['home'],
|
||||
{relativeUrl: '/'}
|
||||
);
|
||||
|
||||
rendered.string.should.equal('home-template');
|
||||
});
|
||||
|
||||
it('can handle preview being set and custom font keys missing', function () {
|
||||
options.data.site._preview = 'test';
|
||||
// The site has fonts set up, but we override them with Theme default fonts (empty string)
|
||||
settingsCacheStub.withArgs('heading_font').returns('Space Grotesk');
|
||||
settingsCacheStub.withArgs('body_font').returns('Noto Sans');
|
||||
|
||||
const rendered = callBodyClassWithContext(
|
||||
['post'],
|
||||
{relativeUrl: '/my-awesome-post/', post: {tags: [{slug: 'foo'}, {slug: 'bar'}]}}
|
||||
);
|
||||
|
||||
rendered.string.should.equal('post-template tag-foo tag-bar');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1126,7 +1126,7 @@ describe('{{ghost_head}} helper', function () {
|
|||
});
|
||||
|
||||
describe('custom fonts', function () {
|
||||
it('includes custom font when set in options data object', async 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 = {
|
||||
|
@ -1136,7 +1136,8 @@ describe('{{ghost_head}} helper', function () {
|
|||
const templateOptions = {
|
||||
site: {
|
||||
heading_font: 'Space Grotesk',
|
||||
body_font: 'Poppins'
|
||||
body_font: 'Poppins',
|
||||
_preview: 'test'
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1151,7 +1152,7 @@ describe('{{ghost_head}} helper', function () {
|
|||
}));
|
||||
});
|
||||
|
||||
it('includes custom font when set in settings cache', async 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');
|
||||
|
@ -1219,6 +1220,56 @@ 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');
|
||||
|
||||
const renderObject = {
|
||||
post: posts[1]
|
||||
};
|
||||
|
||||
await testGhostHead(testUtils.createHbsResponse({
|
||||
templateOptions: {site: {
|
||||
heading_font: '',
|
||||
body_font: '',
|
||||
_preview: 'test'
|
||||
}},
|
||||
renderObject,
|
||||
locals: {
|
||||
relativeUrl: '/post/',
|
||||
context: ['post'],
|
||||
safeVersion: '0.3'
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
const renderObject = {
|
||||
post: posts[1]
|
||||
};
|
||||
|
||||
await testGhostHead(testUtils.createHbsResponse({
|
||||
templateOptions: {site: {
|
||||
// No keys for custom fonts set
|
||||
_preview: 'test'
|
||||
}},
|
||||
renderObject,
|
||||
locals: {
|
||||
relativeUrl: '/post/',
|
||||
context: ['post'],
|
||||
safeVersion: '0.3'
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('members scripts', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue