forked from sunoj/wqzn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurls.js
33 lines (24 loc) · 1.17 KB
/
urls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const url = require(`url`)
const siteUrl = process.env.SITE_URL || `https://www.wqzn.org`
const convertToAbsoluteUrl = path => url.resolve(siteUrl, path)
module.exports.urlForMarkdown = (node, fallback, absolute) => {
// Passing a `path` property in frontmatter will overwrite the
// slug that we build from the folder structure
let slug = node.frontmatter.path ? node.frontmatter.path : fallback
// Remove the version slug from the latest API version docs
// TODO: use env config to add latest API version
if (slug.match(/\/api\/v2\/\S*/i)) {
slug = slug.replace(/\/v2/, ``)
}
return absolute ? convertToAbsoluteUrl(slug) : slug
}
// Create a Gatsby-style URL for resources in Ghost. These are currently the same but they might not always be
module.exports.urlForGhostPost = (postNode, section, absolute) => {
const path = `/${section}/${postNode.slug}/`
return absolute ? convertToAbsoluteUrl(path) : path
}
module.exports.urlForGhostTag = (tagNode, section, absolute) => {
const path = `/${section}/${tagNode.slug}/`
return absolute ? convertToAbsoluteUrl(path) : path
}
module.exports.convertToAbsoluteUrl = convertToAbsoluteUrl