Decode HTML entities in Wordpress titles
This commit is contained in:
1 parent
360e2b2949
commit
73543e709e
5 files changed
+43
-1
No files matched your search
@@ -1,3 +1,5 @@
|
||||
const { neufNormalizer } = require('./src/wordpress')
|
||||
|
||||
module.exports = {
|
||||
siteMetadata: {
|
||||
title: 'Det Norske Studentersamfund',
|
||||
@@ -35,6 +37,7 @@ module.exports = {
|
||||
"**/*/*/settings",
|
||||
"**/*/*/users/me",
|
||||
],
|
||||
normalizer: neufNormalizer,
|
||||
},
|
||||
},
|
||||
'gatsby-plugin-sharp',
|
||||
|
||||
@@ -3,6 +3,25 @@ const path = require('path')
|
||||
const { createFilePath } = require('gatsby-source-filesystem')
|
||||
const { paginate } = require('gatsby-awesome-pagination')
|
||||
|
||||
const neufNormalizer = ({ entities }) => {
|
||||
entities = decodeTitles(entities)
|
||||
return entities
|
||||
}
|
||||
|
||||
exports.neufNormalizer = neufNormalizer
|
||||
|
||||
const Entities = require('html-entities').AllHtmlEntities;
|
||||
const htmlEntities = new Entities();
|
||||
|
||||
const decodeTitles = entities => {
|
||||
return entities.map(e => {
|
||||
if (e.title) {
|
||||
e.title = htmlEntities.decode(e.title)
|
||||
}
|
||||
return e
|
||||
})
|
||||
}
|
||||
|
||||
const getOnlyPublished = edges =>
|
||||
_.filter(edges, ({ node }) => node.status === 'publish')
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"gatsby-source-wordpress": "^3.0.1",
|
||||
"gatsby-transformer-remark": "^2.1.1",
|
||||
"gatsby-transformer-sharp": "^2.1.1",
|
||||
"html-entities": "^1.2.1",
|
||||
"lodash": "^4.17.5",
|
||||
"node-sass": "^4.9.2",
|
||||
"parcel-bundler": "^1.9.4",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
const Entities = require('html-entities').AllHtmlEntities;
|
||||
|
||||
const htmlEntities = new Entities();
|
||||
|
||||
const neufNormalizer = ({ entities }) => {
|
||||
entities = decodeTitles(entities)
|
||||
return entities
|
||||
}
|
||||
|
||||
exports.neufNormalizer = neufNormalizer
|
||||
|
||||
const decodeTitles = entities => {
|
||||
return entities.map(e => {
|
||||
if (e.title) {
|
||||
e.title = htmlEntities.decode(e.title)
|
||||
}
|
||||
return e
|
||||
})
|
||||
}
|
||||
@@ -6108,7 +6108,7 @@ html-comment-regex@^1.1.0:
|
||||
resolved "https://registry.yarnpkg.com/html-comment-regex/-/html-comment-regex-1.1.2.tgz#97d4688aeb5c81886a364faa0cad1dda14d433a7"
|
||||
integrity sha512-P+M65QY2JQ5Y0G9KKdlDpo0zK+/OHptU5AaBwUfAIDJZk1MYf32Frm84EcOytfJE0t5JvkAnKlmjsXDnWzCJmQ==
|
||||
|
||||
html-entities@^1.2.0:
|
||||
html-entities@^1.2.0, html-entities@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
|
||||
integrity sha1-DfKTUfByEWNRXfueVUPl9u7VFi8=
|
||||
|
||||
Reference in new issue
Block a user