-
Notifications
You must be signed in to change notification settings - Fork 8
/
gatsby-ssr.js
35 lines (33 loc) · 872 Bytes
/
gatsby-ssr.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
34
35
import React from 'react'
import urlJoin from 'url-join'
import { withPrefix } from 'gatsby'
exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
const { rss, json, feeds, baseUrl } = pluginOptions
let output = []
for (let feed of feeds) {
let siteUrl = feed.baseUrl || '/'
if (rss) {
let rssurl = urlJoin(siteUrl, feed.name).replace(/\/+$/, '') + '.xml'
output.push(
<link
rel="alternate"
key="gatsby-feed-rss"
type="application/rss+xml"
href={rssurl}
/>
)
}
if (json) {
let jsonurl = urlJoin(siteUrl, feed.name).replace(/\/+$/, '') + '.json'
output.push(
<link
rel="alternate"
key="gatsby-feed-json"
type="application/json"
href={jsonurl}
/>
)
}
}
setHeadComponents(output)
}