Skip to content

Commit 32b75da

Browse files
authored
feat:load cdn resources (#3553)
1 parent 62c4fbb commit 32b75da

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

config/custom-docusaurus-plugin.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const path = require('path');
2+
3+
module.exports = function (context, options) {
4+
return {
5+
name: 'custom-docusaurus-plugin',
6+
configureWebpack(config, isServer, utils) {
7+
return {
8+
output: {
9+
...config.output,
10+
publicPath:
11+
context.i18n.currentLocale === 'en'
12+
? 'https://cdnd.selectdb.com/' :
13+
context.i18n.currentLocale === 'zh-CN' ?
14+
'https://cdnd.selectdb.com/zh-CN/' : 'https://cdnd.selectdb.com/ja/'
15+
},
16+
};
17+
},
18+
};
19+
};

config/ssrTemplate.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
ssrTemplate: `<!DOCTYPE html>
3+
<html <%~ it.htmlAttributes %>>
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
7+
<meta name="generator" content="Docusaurus v<%= it.version %>">
8+
<% if (it.noIndex) { %>
9+
<meta name="robots" content="noindex, nofollow" />
10+
<% } %>
11+
<%~ it.headTags %>
12+
<% it.metaAttributes.forEach((metaAttribute) => { %>
13+
<%~ metaAttribute %>
14+
<% }); %>
15+
<% it.stylesheets.forEach((stylesheet) => { %>
16+
<link rel="stylesheet" href="<%= 'https://cdnd.selectdb.com' %><%= it.baseUrl %><%= stylesheet %>" />
17+
<% }); %>
18+
<% it.scripts.forEach((script) => { %>
19+
<link rel="preload" href="<%= 'https://cdnd.selectdb.com' %><%= it.baseUrl %><%= script %>" as="script">
20+
<% }); %>
21+
</head>
22+
<body <%~ it.bodyAttributes %>>
23+
<%~ it.preBodyTags %>
24+
<div id="__docusaurus">
25+
<%~ it.appHtml %>
26+
</div>
27+
<% it.scripts.forEach((script) => { %>
28+
<script src="<%= 'https://cdnd.selectdb.com' %><%= it.baseUrl %><%= script %>"></script>
29+
<% }); %>
30+
<%~ it.postBodyTags %>
31+
</body>
32+
</html>`,
33+
};

docusaurus.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const versionsPlugin = require('./config/versions-plugin');
33
const VERSIONS = require('./versions.json');
44
const { markdownBoldPlugin } = require('./config/markdown-bold-plugin');
55
const { DEFAULT_VERSION } = require('./src/constant/version');
6+
const { ssrTemplate } = require('./config/ssrTemplate');
7+
const customDocusaurusPlugin = require('./config/custom-docusaurus-plugin');
8+
69

710
// Allow filtering doc versions via environment variable.
811
// Usage: DOCS_VERSIONS="current,4.x" yarn docusaurus build
@@ -139,6 +142,7 @@ const config = {
139142
sidebarPath: require.resolve('./sidebarsReleases.json'),
140143
}),
141144
],
145+
process.env.NODE_ENV === 'development' ? null : customDocusaurusPlugin,
142146
async function tailwindcssPlugin(context, options) {
143147
return {
144148
name: 'docusaurus-tailwindcss',
@@ -671,6 +675,7 @@ const config = {
671675
// },
672676
// ],s
673677
}),
678+
ssrTemplate
674679
};
675680

676681
module.exports = config;

static/.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<IfModule mod_headers.c>
2-
Header set Content-Security-Policy "script-src 'self' widget.kapa.ai www.google.com https://hcaptcha.com https://*.hcaptcha.com https://www.gstatic.com 'unsafe-inline' 'unsafe-eval'; connect-src 'self' proxy.kapa.ai kapa-widget-proxy-la7dkmplpq-uc.a.run.app metrics.kapa.ai https://hcaptcha.com https://*.hcaptcha.com www.google.com; frame-src 'self' www.google.com https://hcaptcha.com https://*.hcaptcha.com; style-src 'self' 'unsafe-inline' https://hcaptcha.com https://*.hcaptcha.com;"
2+
Header set Content-Security-Policy "script-src 'self' https://cdnd.selectdb.com widget.kapa.ai www.google.com https://hcaptcha.com https://*.hcaptcha.com https://www.gstatic.com 'unsafe-inline' 'unsafe-eval'; connect-src 'self' proxy.kapa.ai kapa-widget-proxy-la7dkmplpq-uc.a.run.app metrics.kapa.ai https://hcaptcha.com https://*.hcaptcha.com www.google.com; frame-src 'self' www.google.com https://hcaptcha.com https://*.hcaptcha.com; style-src 'self' https://cdnd.selectdb.com 'unsafe-inline' https://hcaptcha.com https://*.hcaptcha.com; img-src 'self' https://cdnd.selectdb.com data:; font-src 'self' https://cdnd.selectdb.com data:;"
33
</IfModule>

0 commit comments

Comments
 (0)