Skip to content

Commit

Permalink
Merge pull request apollographql#173 from apollographql/no-printer
Browse files Browse the repository at this point in the history
Use Cloudinary instead of gatsby-plugin-printer
  • Loading branch information
jgarrow authored Feb 18, 2021
2 parents 7b52181 + 8bbde79 commit 68ac930
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 830 deletions.
1 change: 0 additions & 1 deletion packages/gatsby-theme-apollo-docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ module.exports = ({
]
}
},
'gatsby-plugin-printer',
...Object.entries(versions).map(([name, branch]) => ({
resolve: 'gatsby-source-git',
options: {
Expand Down
41 changes: 17 additions & 24 deletions packages/gatsby-theme-apollo-docs/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
const git = require('simple-git')();
const {createFilePath} = require('gatsby-source-filesystem');
const {getVersionBasePath, getSpectrumUrl} = require('./src/utils');
const {createPrinterNode} = require('gatsby-plugin-printer');
const {default: getShareImage} = require('@jlengstorf/get-share-image');

function getConfigPaths(baseDir) {
return [
Expand All @@ -21,7 +21,8 @@ async function onCreateNode(
localVersion,
siteName,
subtitle,
sidebarCategories
sidebarCategories,
shareImageConfig
}
) {
const configPaths = getConfigPaths(baseDir);
Expand All @@ -46,39 +47,31 @@ async function onCreateNode(
slug = node.frontmatter.slug; // eslint-disable-line prefer-destructuring
}

let category;
const fileName = parent.name;
const outputDir = 'social-cards';
const {title, sidebar_title, api_reference} = node.frontmatter;

let tagline = subtitle || siteName;
for (const key in sidebarCategories) {
if (key !== 'null') {
const categories = sidebarCategories[key];
const trimmedSlug = slug.replace(/^\/|\/$/g, '');
if (categories.includes(trimmedSlug)) {
category = key;
tagline += ` › ${key}`;
break;
}
}
}

const {title, sidebar_title, api_reference} = node.frontmatter;
createPrinterNode({
id: `${node.id} >>> Printer`,
fileName,
outputDir,
data: {
title,
subtitle: subtitle || siteName,
category
},
component: require.resolve('./src/components/social-card.js')
});

actions.createNodeField({
name: 'image',
node,
value: path.join(outputDir, fileName + '.png')
});
if (shareImageConfig) {
actions.createNodeField({
name: 'image',
node,
value: getShareImage({
title,
tagline,
...shareImageConfig
})
});
}

let versionRef = '';
if (parent.gitRemote___NODE) {
Expand Down
Loading

0 comments on commit 68ac930

Please sign in to comment.