Skip to content

Commit

Permalink
Интеграция типографа
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored and another-guy committed Mar 4, 2019
1 parent 771dc46 commit 04095c0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ module.exports = {
},
'gatsby-plugin-react-helmet',
'gatsby-plugin-catch-links',
'gatsby-remark-typography', // only for Russian translation
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"request-promise": "^4.2.2",
"rimraf": "^2.6.1",
"slugify": "^1.2.1",
"typograf": "^6.8.0",
"unist-util-visit": "^1.1.3"
},
"engines": {
Expand Down
23 changes: 23 additions & 0 deletions plugins/gatsby-remark-typography/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const Typograf = require('typograf');

exports.onPreExtractQueries = async ({store, getNodes}) => {
const tp = new Typograf({locale: ['ru']});
const fields = ['title', 'content'];
const markdownNodes = getNodes().filter(node => {
return node.internal.type === 'MarkdownRemark';
});

markdownNodes.forEach(node => {
fields.forEach(field => {
const value = node.frontmatter[field];

if (!value) {
return;
}

node.frontmatter[field] = tp.execute(value);
});
});
};
4 changes: 4 additions & 0 deletions plugins/gatsby-remark-typography/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "gatsby-remark-typography",
"version": "0.0.1"
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12229,6 +12229,11 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typograf@^6.8.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/typograf/-/typograf-6.8.0.tgz#103447a52c23bd19cfe65b81f4e95d36b71879a3"
integrity sha512-TsAXy+fDS0g9H6W9CBhnFlvBsRp7Hq5K/fuuBn5X0P86Me9V/YiSTzuXR6TN83AZ0QXyui9o4LLxQFOPmSyxMA==

ua-parser-js@^0.7.18:
version "0.7.18"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.18.tgz#a7bfd92f56edfb117083b69e31d2aa8882d4b1ed"
Expand Down

0 comments on commit 04095c0

Please sign in to comment.