From 04095c05645464f3b4be2183a9fbf83cb16e0cbf Mon Sep 17 00:00:00 2001 From: Alexey Pyltsyn Date: Sun, 3 Mar 2019 14:17:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D1=82=D0=B5=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=82=D0=B8=D0=BF=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=84=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatsby-config.js | 1 + package.json | 1 + .../gatsby-remark-typography/gatsby-node.js | 23 +++++++++++++++++++ plugins/gatsby-remark-typography/package.json | 4 ++++ yarn.lock | 5 ++++ 5 files changed, 34 insertions(+) create mode 100644 plugins/gatsby-remark-typography/gatsby-node.js create mode 100644 plugins/gatsby-remark-typography/package.json diff --git a/gatsby-config.js b/gatsby-config.js index 03d8ea04d..58e3bd1ff 100755 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -160,5 +160,6 @@ module.exports = { }, 'gatsby-plugin-react-helmet', 'gatsby-plugin-catch-links', + 'gatsby-remark-typography', // only for Russian translation ], }; diff --git a/package.json b/package.json index 293cb2287..de8035421 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/plugins/gatsby-remark-typography/gatsby-node.js b/plugins/gatsby-remark-typography/gatsby-node.js new file mode 100644 index 000000000..fe32f7ce0 --- /dev/null +++ b/plugins/gatsby-remark-typography/gatsby-node.js @@ -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); + }); + }); +}; diff --git a/plugins/gatsby-remark-typography/package.json b/plugins/gatsby-remark-typography/package.json new file mode 100644 index 000000000..dd42e68cd --- /dev/null +++ b/plugins/gatsby-remark-typography/package.json @@ -0,0 +1,4 @@ +{ + "name": "gatsby-remark-typography", + "version": "0.0.1" +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index a3859f100..deb7190eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"