Skip to content

Commit d5d24ce

Browse files
authored
Merge pull request #63 from holidayextras/prismicLinkResolver
Allow link to resolve using slug
2 parents 037c88a + a8b2334 commit d5d24ce

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@holidayextras/static-site-generator",
3-
"version": "8.0.9",
3+
"version": "8.0.10",
44
"description": "Holiday Extras Static Site Generator in metalsmith / react",
55
"repository": {
66
"type": "git",
@@ -30,6 +30,7 @@
3030
"clone": "^1.0.2",
3131
"debug": "^2.2.0",
3232
"jsonp": "^0.2.0",
33+
"lodash": "^4.17.21",
3334
"meta-marked": "^0.4.0",
3435
"metalsmith": "^2.3.0",
3536
"metalsmith-assets": "^0.1.0",

src/getDataSource.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import prismic from './metalsmith-prismic'
22
import hxseo from './getHXSEOContent'
33
import apiCaller from './apiCaller'
4+
import _ from 'lodash'
45

56
const getDataSource = (opts) => {
67
if (!opts.dataSource) return false
@@ -15,6 +16,12 @@ const getDataSource = (opts) => {
1516
'accessToken': opts.dataSource.accessToken,
1617
'linkResolver': configLinkResolver || function (ctx, doc) {
1718
if (doc.isBroken) return ''
19+
if (_.has(doc, 'data.slug.json.value')) {
20+
const regExpDomain = new RegExp(`.*${opts.config.domainSettings.domainLive}`)
21+
// Strip domain (+ everything before it) off of the slug in case it was added by mistake
22+
const slug = doc.data.slug.json.value
23+
return slug.replace(regExpDomain, '')
24+
}
1825
return '/' + doc.uid
1926
}
2027
})

0 commit comments

Comments
 (0)