Skip to content

Commit 2ac6161

Browse files
committed
fix(theme): 设置 headers 后,外部资源添加 crossorigin
1 parent b031b04 commit 2ac6161

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

docs/.vuepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default defineUserConfig({
2828
{
2929
rel: 'stylesheet',
3030
href: '//at.alicdn.com/t/font_2410206_mfj6e1vbwo.css',
31+
crossorigin: true,
3132
},
3233
],
3334
[
@@ -36,20 +37,23 @@ export default defineUserConfig({
3637
rel: 'stylesheet',
3738
// zhaobc挑选的图标
3839
href: '//at.alicdn.com/t/c/font_4647860_t3wvzckeetc.css',
40+
crossorigin: true,
3941
},
4042
],
4143
[
4244
'script',
4345
{
4446
// 百度统计
4547
src: '//hm.baidu.com/hm.js?85e80625eddf91d81d9535565850722b',
48+
crossorigin: true,
4649
},
4750
],
4851
[
4952
'script',
5053
{
5154
// Clarity
5255
src: '/assets/js/clarity.js',
56+
crossorigin: true,
5357
},
5458
],
5559
],

docs/.vuepress/styles/zhaobc.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
}
110110

111111
/* 调整评论框宽度 */
112-
#vp-comment {
112+
.vp-comment {
113113
max-width: var(--content-width, 740px);
114114
margin: 0 auto;
115115
padding: 0 2.5rem;
@@ -123,10 +123,10 @@
123123
&.theme-container {
124124
.vp-breadcrumb,
125125
.vp-page-title,
126-
.theme-hope-content,
126+
[vp-content],
127127
.content-after-container,
128128
.vp-page-meta,
129-
#vp-comment {
129+
.vp-comment {
130130
max-width: 1080px;
131131
}
132132

docs/posts/dev/python-playground.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tag:
1414
head:
1515
- - meta
1616
- name: description
17-
content: Python Playground, Python 演练场
17+
content: Python Playground, Python 演练场, python repl, python, repl
1818
---
1919

2020
# Python Playground 演练场
@@ -330,6 +330,8 @@ api // vercel 要求,必须放到根目录下
330330

331331
开发中不熟悉 Pyodide, 也不熟悉 MonoEditor, Web Worker 所以遇到了不少问题,这里简单记录一下。
332332

333+
### SharedArrayBuffer 使用问题
334+
333335
- SharedArrayBuffer is not defined
334336
在处理 `stdin` 中,用到了 SharedArrayBuffer,但是使用上有些限制,需要配置 `headers`
335337

@@ -418,6 +420,25 @@ api // vercel 要求,必须放到根目录下
418420

419421
repl 和 前台的这两个输入流的类型必须一致。
420422

423+
### 跨域设置问题
424+
425+
为了使用 `SharedArrayBuffer` 主站设置了以下 headers:
426+
427+
- `Cross-Origin-Opener-Policy` (_COOP_)
428+
- `Cross-Origin-Embedder-Policy` (_COEP_)
429+
- `Cross-Origin-Resource-Policy` (_CORP_)
430+
431+
```txt
432+
Cross-Origin-Opener-Policy: same-origin
433+
Cross-Origin-Embedder-Policy: require-corp
434+
Cross-Origin-Resource-Policy: same-site
435+
```
436+
437+
其中,设置 `Cross-Origin-Resource-Policy` 是为了嵌入的 `iframe` 里的 Python Playground,能正常使用。
438+
除此之外,还设置了 `iframe` 的属性 `allow="cross-origin-isolated"`
439+
440+
由于设置了上次 header 会导致主站的一些 `js`, `css` 等加载有问题,需要加上 `crossorigin` 属性。
441+
421442
## 类似功能
422443

423444
其他网站已提供现成的功能,可以直接使用。本次开发中也借鉴了它们,再次表示感谢。

0 commit comments

Comments
 (0)