forked from ShashiSubramanya/embed-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-config.js
237 lines (225 loc) · 7.69 KB
/
gatsby-config.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
require('dotenv').config();
const asciidoc = require('asciidoctor')();
const config = require('./docs/src/configs/doc-configs');
const getPathPrefix = () => {
if (process.env.BUILD_ENV === config.BUILD_ENVS.LOCAL) {
return null;
}
return 'docs';
};
const getPath = (path) =>
getPathPrefix() ? `${path}/${getPathPrefix()}` : path;
class CustomDocConverter {
constructor() {
this.baseConverter = asciidoc.Html5Converter.$new();
}
/**
* Check if inline_anchor target is for transformation or not
* @param {string} target - inline_anchor target i.e. href
* @returns {boolean} true if transformation is needed else false
*/
isTransformLink(target) {
return (
!target.includes(`{{${config.NAV_PREFIX}}}`) &&
!target.includes(`{{${config.PREVIEW_PREFIX}}}`) &&
!target.includes(`{{${config.TS_HOST_PARAM}}}`) &&
!target.includes('www.') &&
!target.startsWith('http')
);
}
/**
* Convert is used to return html node string based on transform or conditions
* @param {any} node - The concrete instance of AbstractNode to convert.
* @param {string} transform - An optional string transform that hints at which transformation should be applied to this node.
* @returns {string} html node string
*/
convert(node, transform) {
// checking anchor node type
if (node.getNodeName() === 'inline_anchor') {
let anchorMarkup = '';
// get anchor target set inside adoc file
let target = node.getTarget();
// get anchor attributes
const attributes = node.getAttributes();
if (this.isTransformLink(target)) {
// check if link is for 'Visual Embed SDK' documents or not
if (target.includes(config.VISUAL_EMBED_SDK_PREFIX)) {
anchorMarkup = `${getPath(config.DOC_REPO_NAME)}/${
config.TYPE_DOC_PREFIX
}${target.replace(
`{{${config.VISUAL_EMBED_SDK_PREFIX}}}`,
'',
)}`;
} else if (!target.startsWith('#')) {
target = target.substring(
target.lastIndexOf(':') + 1,
target.lastIndexOf('.html'),
);
anchorMarkup = `{{${config.NAV_PREFIX}}}={{${target}}}`;
}
// attribute handling - DO NOT CHANGE ORDER OF IFs
if (attributes.fragment) {
anchorMarkup += `#${attributes.fragment}`;
}
anchorMarkup = `href="${anchorMarkup}"`;
if (attributes.window) {
anchorMarkup += ` target="${attributes.window}"`;
}
return `<a ${anchorMarkup}>${node.getText()}</a>`;
}
}
return this.baseConverter.convert(node, transform);
}
}
console.log(getPath(config.DOC_REPO_NAME));
module.exports = {
pathPrefix: getPath(config.DOC_REPO_NAME),
siteMetadata: {
title: 'tseverywhere-docs',
},
plugins: [
'gatsby-plugin-sass',
{
resolve: 'gatsby-plugin-page-creator',
options: {
path: `${__dirname}/docs/src/pages`,
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'pages',
path: `${__dirname}/docs/src/pages/`,
},
__key: 'pages',
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'asciidocs',
path: `${__dirname}/docs/src/asciidocs/`,
},
__key: 'asciidocs',
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'common',
path: `${__dirname}/docs/src/asciidocs/common/`,
},
__key: 'asciidocs_common',
},
{
resolve: 'gatsby-plugin-intl',
options: {
// language JSON resource path
path: `${__dirname}/docs/src/intl`,
// supported language
languages: ['en'],
// language file path
defaultLanguage: 'en',
// option to redirect to `/en` when connecting `/`
redirect: false,
},
},
{
resolve: 'gatsby-transformer-asciidoc',
options: {
safe: 'server',
attributes: {
showtitle: true,
imagesdir: '/doc-images',
path: `${__dirname}/docs/src/asciidocs/partials`,
},
fileExtensions: ['ad', 'adoc'],
converterFactory: CustomDocConverter,
},
},
{
resolve: 'gatsby-transformer-rehype',
options: {
mediaType: 'text/html',
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'htmlFiles',
path: `${__dirname}/static/typedoc/`,
},
__key: 'htmlFiles',
},
'gatsby-plugin-catch-links',
{
resolve: 'gatsby-plugin-manifest',
options: {
name: 'ThoughtSpot Everywhere Documentation',
short_name: 'Documentation',
icon: `${__dirname}/docs/src/assets/icons/favicon.png`,
},
},
'gatsby-plugin-output',
{
resolve: 'gatsby-plugin-algolia',
options: {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.ALGOLIA_ADMIN_KEY,
queries: require(`${__dirname}/docs/src/utils/algolia-queries`)
.queries,
},
},
{
resolve: 'gatsby-plugin-sitemap',
options: {
query: `
{
allAsciidoc {
edges {
node {
pageAttributes {
pageid
}
}
}
}
}`,
resolveSiteUrl: () => config.SITE_URL,
resolvePages: ({ allAsciidoc: { edges } }) => {
const asciiNodeSet = new Set();
edges.forEach((edge) => {
if (
edge.node &&
edge.node.pageAttributes &&
edge.node.pageAttributes.pageid
) {
asciiNodeSet.add(edge.node.pageAttributes.pageid);
}
});
const paths = [];
for (const item of asciiNodeSet) {
paths.push({ path: `?pageid=${item}` });
}
return paths;
},
serialize: ({ path }) => {
return {
url: path,
};
},
},
},
{
resolve: 'gatsby-plugin-env-variables',
options: {
allowList: ['BUILD_ENV'],
},
},
{
resolve: 'gatsby-plugin-vercel',
options: {
// (optional) Prints metrics in the console when true
debug: false,
},
},
],
};