这篇文章展示了 Jekyll(基于 kramdown 解析器)所支持的绝大多数 markup 语法,用于测试主题样式或作为撰写文章的参考规范。
1. 基础排版 (Text Formatting)
这是普通的段落文本。你可以在段落中使用 粗体文本 、斜体文本 、粗斜体 ,或者删除线被划掉的内容。
还可以使用 标记代码 (inline code),或者添加脚注来补充说明 。
通过 Kramdown 缩写扩展,你可以定义缩写,例如鼠标悬停在 HTML 上会显示全称。
2. 标题层级 (Headings)
三级标题 (H3)
四级标题 (H4)
五级标题 (H5)
六级标题 (H6)
技巧 :Jekyll 支持通过 {: #custom-id} 显式为标题自定义 ID。
3. 列表 (Lists)
无序列表
有序列表
第一步:准备 Jekyll 环境
第二步:编写 Markdown 文件
第三步:运行 jekyll serve 构建
任务列表 (Task Lists)
4. 引用与块级元素 (Blockquotes)
这是一个单行块级引用 (Blockquote)。
这是一个嵌套的引用块。
可以在这里提供出处或引申信息。
5. 代码高亮 (Code Blocks)
Jekyll 支持通过标准的 Markdown 语法高亮代码块。并且我们启用了 Rouge 的行号显示:
1
2
3
4
5
6
// JavaScript 示例
function greet ( name ) {
console . log ( `Hello, ${ name } ! Welcome to Jekyll.` );
}
greet ( ' Developer ' );
同时,Jekyll 原生支持 Liquid 的 highlight 标签:
# Python 示例
def calculate_factorial ( n ):
if n == 0 :
return 1
return n * calculate_factorial ( n - 1 )
print ( f " Factorial of 5: { calculate_factorial ( 5 ) } " )
Diff 差异对比代码块 (Material Design 3 Diff & Patch)
主题原生支持 Material Design 3 风格的高性能 Diff 差异高亮与多语言语法高亮共存 。自动统计并展示新增与删除行数徽标,区分注释段落与代码变更,行号与行高 100% 像素级对齐,并支持全宽行级柔和背景过渡:
1. 编程语言语法高亮 + Diff 共存 (Python[diff])
在任意语言标识符后追加 [diff](如 Python[diff]、js[diff]、cpp[diff]、rust[diff]),即可在保留完整语言语法高亮(关键字、函数、字符串等着色)的同时,完美应用行级 Diff 增删对比:
1
2
3
4
5
6
7
8
def calculate_discount ( price : float , is_member : bool ) -> float :
- if is_member :
- # 普通老会员 9 折
- return price * 0.9
+ if is_member :
+ # VIP 尊享会员全面升级为 8 折
+ return price * 0.8
return price
2. 无语法高亮的纯文本 Diff (txt[diff])
使用 txt[diff] 或 text[diff],可以展示干净纯粹的纯文本差异对比,支持 # 注释段落识别与行列统计:
1
2
3
4
5
6
7
8
9
# 原始字节: 商业售卖模式 (False)
- Offset 0x860cf1c0: 00
- Offset 0x860cf208: 00
- Offset 0x860cf24c: 00
# 补丁字节: 原生测试全免模式 (True)
+ Offset 0x860cf1c0: 01
+ Offset 0x860cf208: 01
+ Offset 0x860cf24c: 01
3. 标准 Unified Patch / Diff (diff)
1
2
3
4
5
6
7
8
@@ -10,6 +10,7 @@
import asyncio
import aiohttp
+ import orjson
async def fetch_user_data(user_id: int):
- return await legacy_fetch(user_id)
+ return await optimized_fetch(user_id)
6. 表格 (Tables)
这里展示了一个标准对齐方式的表格。
过滤器/属性
说明
示例输入
示例输出
date_to_string
日期转为字符串
site.time
01 Aug 2026
upcase
字符转大写
"hello"
HELLO
size
获取数组或字符串长度
page.tags
4
图片展示
图:展示支持图片说明文本的效果
8. Jekyll 特有扩展 (kramdown & Liquid)
属性列表 (Attribute Lists)
你可以直接给下一个元素添加 CSS 类名或内联样式:
这是一个带有自定义 CSS 类和背景样式的警告段落。
定义列表 (Definition Lists)
Jekyll / Liquid
基于 Ruby 的静态网站生成器。
kramdown
Jekyll 默认使用的 Markdown 解析引擎,支持丰富的扩展语法。
可以有多个解释。
数学公式 (LaTeX)
如果你的主题引入了 MathJax/KaTeX,可以渲染数学公式:
\[E = mc^2\]
Liquid 变量调用示例
本篇文章标题 :Jekyll 完整 Markup 与 Markdown 语法展示
文章发布时间 :2026年07月31日
标签数量 :4 个
9. GitHub Alerts (提示框)
我们通过自研的 AST 转换插件,原生支持了 GitHub 风格的 Alerts。在段落前加上 > [!NOTE] 等标记即可触发:
info Note
这是一个 Note 提示框。用于强调一般性的补充信息。
lightbulb Tip
这是一个 Tip 提示框。用于提供有用的建议或快捷方式。
report Important
这是一个 Important 提示框。用于向用户传达实现其目标必不可少的关键信息。
warning Warning
这是一个 Warning 提示框。用于提醒用户注意潜在的风险。
dangerous Caution
这是一个 Caution 提示框。用于警告可能导致数据丢失或严重后果的高危操作。
10. 可折叠详情区 (Details & Summary)
你可以直接使用原生 HTML 的 <details> 和 <summary> 标签来包裹长文本或超长代码。我们已经为其适配了 MD3 风格的展开面板样式。
lightbulb Tip
如果你想在 <details> 内部继续使用 Markdown 语法(如代码块、加粗等),必须在 <details> 标签上添加 markdown="1" 属性,并且在 <summary> 和内容之间留一个空行 。
点击展开查看详细构建日志
1
2
3
4
5
6
7
8
9
$ bundle exec jekyll build
Configuration file: /workspace/_config.yml
Source: /workspace
Destination: /workspace/_site
Incremental build: disabled. Enable with --incremental
Generating...
Jekyll Feed: Generating feed for posts
done in 0.548 seconds.
Auto-regeneration: disabled. Use --watch to enable.
日志显示构建成功。
11. Mermaid 原生图表引擎
本博客内置了高性能、按需懒加载 (Lazy Load) 的 Mermaid 渲染支持。你只需要用标准的代码块并指定语言为 mermaid 即可绘制流程图、时序图、甘特图等。
graph TD;
A[用户请求] --> B{认证校验};
B -- 成功 --> C[请求后端 API];
B -- 失败 --> D[拒绝访问];
C --> E[返回组合数据];
D --> F[重定向到登录页];
12. 颜色色块自动预览 (Color Swatches)
在技术博客中,我们经常会讨论到颜色代码。现在,只要你在行内代码中写入规范的颜色值,系统就会自动在旁边生成一个 MD3 风格的圆形色块进行预览。
支持 HEX、RGB(A) 和 HSL(A) 格式:
主色调使用 #FF5733 或 #0061A4
也可以带透明度,比如 #0061A480
或者使用 rgb(52, 152, 219) 和 rgba(52, 152, 219, 0.5)
HSL 同样支持:hsl(120, 100%, 25%)
13. 3D 模型原生渲染 (STL, GLTF & GLB)
现在你可以直接在博客中交互预览多种 3D 模型格式(包括 STL、GLTF 与 GLB)。只需将 3D 数据或模型路径包裹在对应的代码块中,前端的三维引擎会自动将其渲染为可通过鼠标或手势拖拽旋转、支持物理光照材质的三维视口,完美契合 MD3 质感。
13.1 STL 基础立方体渲染演示
solid cube
facet normal 0 0 -1
outer loop
vertex 0 0 0
vertex 1 1 0
vertex 1 0 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex 0 0 0
vertex 0 1 0
vertex 1 1 0
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 0 1
vertex 1 0 1
vertex 1 1 1
endloop
endfacet
facet normal 0 0 1
outer loop
vertex 0 0 1
vertex 1 1 1
vertex 0 1 1
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 0 0 0
vertex 1 0 0
vertex 1 0 1
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 0 0 0
vertex 1 0 1
vertex 0 0 1
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 0 1 0
vertex 0 1 1
vertex 1 1 1
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 0 1 0
vertex 1 1 1
vertex 1 1 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 0 0 0
vertex 0 0 1
vertex 0 1 1
endloop
endfacet
facet normal -1 0 0
outer loop
vertex 0 0 0
vertex 0 1 1
vertex 0 1 0
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 1 0 0
vertex 1 1 0
vertex 1 1 1
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 1 0 0
vertex 1 1 1
vertex 1 0 1
endloop
endfacet
endsolid
13.2 动态 JS 场景构建 (stljs)
lightbulb Tip
引用外部文件与现场 JS 渲染 🎨
如果模型文件太大,你不需要将冗长的代码直接贴在文章里。你可以在 stl 中直接写入本地 STL 文件的路径(如 /assets/models/example.stl)或外部 URL,渲染器会自动去下载并解析。
此外,我们还支持一种更硬核的极客玩法:使用 stljs 代码块。这允许你直接编写 JavaScript 三维场景构建代码 !在代码内部,你已经拥有了预置好的 THREE, scene, 和 material。例如,下面是一段召唤一组抽象几何体的代码:
const mesh = new THREE.Group();
const cylGeo = new THREE.CylinderGeometry(8, 8, 40, 32);
const cyl = new THREE.Mesh(cylGeo, material);
cyl.position.y = 20;
mesh.add(cyl);
const sphGeo = new THREE.SphereGeometry(12, 32, 32);
const sph1 = new THREE.Mesh(sphGeo, material);
sph1.position.set(-10, 0, 0);
mesh.add(sph1);
const sph2 = new THREE.Mesh(sphGeo, material);
sph2.position.set(10, 0, 0);
mesh.add(sph2);
// 为自动缩放镜头设置一个虚拟的包裹盒
mesh.geometry = new THREE.BoxGeometry(40, 60, 24);
mesh.geometry.computeBoundingBox();
scene.add(mesh);
13.3 进阶 3D 格式:GLTF / GLB 原生渲染与骨骼动画 (GLTF / GLB with PBR & Animations)
除了传统的单一网格 STL 格式外,本主题现已全面升级,支持工业级 GLTF 2.0 / GLB 3D 模型格式 。
核心渲染特性
PBR 真实感物理渲染 :完整支持粗糙度、金属度、法线贴图、环境反射与自发光材质;
电影级打光与色调映射 :启用 ACESFilmic 色调映射(Tone Mapping),结合柔和半球环境光与主次平行漫反射光源;
骨骼动画 (Skeletal Animation) :内置 THREE.AnimationMixer,自动检测并实时循环播放模型内嵌的骨骼骨骼动画或变形目标(Morph Targets);
视锥自适应与全触控轨道控制 :基于模型的包围盒(Bounding Box)自动计算中心锚点与相机视距,支持 PC 端鼠标拖拽、滚轮缩放与移动端双指手势平移旋转。
语法示例
在 Markdown 中使用 glb 或 gltf 代码块,内部写入模型绝对路径或外部 URL(也支持内联嵌入标准 GLTF JSON 字符串):
1
2
3
``` glb
/assets/models/ori_and_the_blind_forest.glb
```
效果展示
/assets/models/ori_and_the_blind_forest.glb
info Note
模型资产归属与开源许可声明 :
“Ori and the Blind Forest” (https://skfb.ly/otELU) by Dasha Klyusova is licensed under Creative Commons Attribution (http://creativecommons.org/licenses/by/4.0/).
14. GeoJSON 交互式地图
同样地,地图数据也能原生渲染!只需要使用 geojson 或 topojson。系统会懒加载 Leaflet + MapLibre GL 矢量地图组件,将坐标系精确绘制在全球地图上(使用 OpenFreeMap 极简风格矢量底图),并自动计算最佳缩放视角。
lightbulb Tip
坐标点 (Point) 和 范围 (Polygon)
只要在 Markdown 里写上 geojson 代码块,渲染器会自动分别生成独立的地图,并且自适应缩放到最合适的观看距离。你可以点击图元查看附带的 Properties 属性。
示例 1:单点坐标 (Point)
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [121.4442, 31.1895]
},
"properties": {
"name": "宛平南路600号 (Point)",
"description": "上海市精神卫生中心"
}
}
]
}
示例 2:范围多边形 (Polygon)
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[116.38, 39.90],
[116.42, 39.90],
[116.42, 39.93],
[116.38, 39.93],
[116.38, 39.90]
]
]
},
"properties": {
"name": "故宫范围 (Polygon)",
"description": "这是一个自定义的多边形"
}
}
]
}
在编写技术文档、快捷键说明时,你可以使用原生 <kbd> 标签。我们为其量身定制了微立体质感的物理键帽样式,这让快捷键的指引在视觉上更加清晰且极具质感。
快速打开命令面板:Ctrl + Shift + P
保存文件并退出:Win + S 然后按 Esc
在终端中止当前进程:Ctrl + C
16. 文件下载卡片 (File Download Card)
如果你需要提供 Cloudflare R2 或者其他云存储的外部文件下载链接,不要使用干瘪的普通超链接。Jekyll 原生支持 Liquid include 标签,我们为你定制了一个 MD3 风格的下载展示 UI。
你只需要在文章中插入:
1
2
3
4
5
6
7
8
9
{% include file_download.html
name = "2026_Q3_Financial_Report.pdf"
size = "4.2 MB"
date = "2026-08-01"
icon = "picture_as_pdf"
color = "error"
url = "https://example.com/file.pdf" %}
实际渲染效果:
17. 媒体相册与全屏灯箱 (MD3 Gallery & Lightbox)
在撰写博客时,经常需要展示多张照片、截图或是演示视频。为了提供最优雅的浏览体验,本博客最新引入了 自动相册 (Smart Gallery) 与 全屏悬浮灯箱 (MD3 Lightbox Viewer) 功能。
自动组合的智能相册 (Smart Gallery)
你不需要在 Markdown 中书写任何复杂的 HTML 代码。只要你将多张图片连续放置(即换行连续写 ![](),且中间不穿插其他文本),底层的引擎就会在页面加载时,自动识别并将它们打包成一个高级相册组件。
生成的相册具有以下特性:
上大图、下缩略图 :采用现代化的 16:9 黄金比例展示主视图,下方提供可横向滑动的缩略图列表。
无缝切换动画 :点击下方缩略图时,主视图会执行流畅的淡入淡出(Crossfade)切换动画,避免生硬的画面闪烁。
MD3 设计语言 :选中的缩略图会有一圈柔和的强调色边框(Primary Color),并且带有细微的不透明度渐变反馈。
下面是一个由 5 张图组成的相册示例,你可以点击下方的小图进行切换:
全屏沉浸式灯箱查看器 (Lightbox Viewer)
不仅相册里的大图可以点击,即便是文章中单独出现的一张图片,当你点击它时,都会立即唤出一个沉浸式的全屏灯箱。
lightbulb Tip
操作指南 :
缩放 :在全屏状态下,你可以直接使用鼠标滚轮进行无级缩放。或者点击右上角的 🔍 放大/缩小按钮。
拖拽平移 :当图片被放大后,你可以按住鼠标左键(或在手机上使用手指)随意拖动图片,查看细节。
快捷键切换 :如果你是在相册中打开了灯箱,可以使用键盘上的 ← 左箭头 和 → 右箭头 快速翻页。
退出 :点击右上角的关闭按钮、点击背景黑色模糊区域,或者直接按下键盘上的 Esc 键即可退出全屏。
为了展示这个效果,这里有一张孤立的宽幅图片,点击它感受一下毛玻璃背景(Backdrop Blur)衬托下的极致阅图体验吧:
18. Liquid 进阶语法 (Liquid Advanced Syntax)
除了前面展示的基础变量和部分功能外,Liquid 还是一个非常成熟的模板控制引擎。通过以下进阶语法,你可以让你的静态博客拥有极强的动态生成能力。
18.1 逻辑控制 (Control Flow)
Liquid 允许你在 Markdown 中进行各种逻辑判断,这在编写复杂的主题模板或根据条件显示特定内容时非常有用。
if / elsif / else 与 unless
unless 是 if 的反面,当条件为假时执行。
1
2
3
4
5
6
7
8
9
10
11
12
13
{% if page . comments %}
<p>评论功能已开启!快来留言吧。</p>
{% elsif page . title == "特殊文章" %}
<p>这是一篇特殊文章。</p>
{% else %}
<p>默认内容。</p>
{% endif %}
{% unless page . draft %}
<p>这篇文章不是草稿,已向公众展示。</p>
{% endunless %}
case / when
当你需要检查一个变量是否有多个特定值时:
1
2
3
4
5
6
7
8
9
10
11
{% assign animal = "cat" %}
{% case animal %}
{% when "dog" %}
<p>汪汪!</p>
{% when "cat" %}
<p>喵喵!</p>
{% else %}
<p>未知动物。</p>
{% endcase %}
18.2 循环与遍历 (Iteration)
你可以使用 for 循环遍历数组,或者直接迭代一定次数。这在生成文章列表、标签页时必不可少。
基础遍历与限制
1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- 遍历标签数组,只输出前两个 -->
<ul>
{% for tag in page . tags limit : 2 %}
<li>标签: {{ tag }} </li>
{% endfor %}
</ul>
<!-- 循环固定次数,或者反向循环 -->
{% for i in ( 1 .. 3 ) reversed %}
<p>倒计时:{{ i }} </p>
{% endfor %}
Cycle (轮流输出)
在循环中非常有用的语法,可以在每次迭代时交替输出不同的类名或字符串,通常用于给列表的奇偶行加上不同的颜色:
1
2
3
4
5
{% for i in ( 1 .. 4 ) %}
<div class="{% cycle 'odd-row' , 'even-row' %} ">项目 {{ i }} </div>
{% endfor %}
Tablerow (自动生成 HTML 表格)
tablerow 可以自动帮你把一维数组渲染为 HTML 的 <table> 元素。
1
2
3
4
5
6
7
<table>
{% tablerow tag in page . tags cols : 2 %}
{{ tag }}
{% endtablerow %}
</table>
18.3 变量操作与逃逸 (Variables & Raw)
assign 与 capture
assign 用于单行变量赋值,而 capture 可以把一大块包含 Liquid 渲染内容的块级元素打包存进一个变量里。
1
2
3
4
5
6
7
8
9
10
11
12
13
{% assign primary_color = "#0061A4" %}
{% capture alert_html %}
<div style="color: {{ primary_color }} ">
<h4>注意</h4>
<p>这是被捕获的一段复杂 HTML 文本。</p>
</div>
{% endcapture %}
<!-- 在其他地方输出被捕获的内容 -->
{{ alert_html }}
如果你正在写技术博客教别人怎么用 Liquid(就像本文一样),你可以用 raw 让 Liquid 停止解析大括号。用 comment 则可以写只在源码可见、连编译后的 HTML 里面都不会出现的极密注释。
’ %}
1
2
3
4
5
6
7
{% raw
这里面的 {{ 不会被解析 }} ,{% include 也会失效 。
{% endraw
{% comment
这个注释在 `jekyll build ` 的时候会被彻底抹去,用户 F12 绝对看不到。
{% endcomment
18.4 丰富的过滤器 (Filters)
过滤器用于修改变量的输出结果,你可以用管道符 | 把它们串联起来。
1
2
3
4
5
6
7
8
* **转为大写**: {{ "hello world" | upcase }} => HELLO WORLD
* **首字母大写**: {{ "hello world" | capitalize }} => Hello world
* **去除 HTML 标签**: {{ "<b>粗体</b>" | strip_html }} => 粗体
* **截断字符**: {{ "这是一段非常长的测试文本,超过长度会被截断。" | truncate : 12 , "..." }} => 这是一段非常长...
* **默认值后备**: {{ page . author | default : "佚名" }} => 佚名
* **获取数组首项**: {{ page . tags | first }}
18.5 Jekyll 专属超级链接 (Post ID & Link)
在文章中插入站内链接时,千万不要把 URL 写死。推荐使用我们扩展的 post_id 标签,只需传入文章 Front Matter 中定义的 id(例如 demo、a8c9n3、v69yxm),系统会自动解析并生成固定链接路由,哪怕未来你调整了目录结构或日期,站内链接也永远不会失效/404 :
1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- 极简推荐:直接传入文章的 id,写作体验极其顺畅! -->
[了解 Jekyll 语法展示]({% post_id demo %} )
<!-- 也支持锚点跳转 -->
[跳转到特定章节]({% post_id demo #1-基础排版-text-formatting %} )
<!-- 兼容旧版 post_url 直接传 id 或文件名 -->
[历史语法兼容]({% post_url demo %} )
<!-- 链接到普通页面或静态资源文件 -->
[下载这张图片]({% link assets/images/jekyll.jpg %} )
19. 定制化媒体播放器 (MD3 Player)
Antigravity 主题支持自动拦截浏览器原生的 <video> 和 <audio> 标签,并将其替换为符合 Material Design 3 (MD3) 设计规范的毛玻璃风格自定义播放器。
只需在插入音视频时带有 controls 属性,系统便会自动接管。
视频播放器 (Video)
带有全屏支持和底部悬浮控制栏的响应式视频播放器:
音乐播放器 (Audio)
简洁美观的内嵌式音频播放栏,支持丝滑的进度拖拽:
RIP Kavinsky
自定义大字号文本 (Custom Size Markup)
如果你想在正文中展示一些极具视觉冲击力的超大文本,又不想使用原生的 Markdown 标题标签(比如 <h1> 会导致被强制收录到侧边栏目录中),你可以使用我们独创的 [size:xx] 语法。
lightbulb Tip
语法支持
[size:你的大小]大文本内容[/size]
只要标签内部有换行,它就会被渲染成占据全宽的块级大字体段落,否则将作为行内文本。
示例展示:
这是一个内联的巨大文本 HELLO 测试。
这是一个跨行的大字号块级文本!
支持 Markdown 原生语法:加粗 ,斜体 ,链接
甚至可以使用像素单位 (80px) 来实现更夸张的效果。
20. 丰富的链接预览卡片 (Rich Link Previews)
无论是指向本站的其他文章,还是指向站外的第三方链接,你都可以通过在 Markdown 链接末尾加上 {: .preview } 属性,让编译器自动在构建时抓取目标网站的信息,并生成一个极具质感、符合 MD3 规范的链接预览卡片(类似 Telegram 或 Twitter 的富文本链接)。
内链卡片预览
自动读取本站文章的标题、摘要和头图。直接使用 {% post_id 文章ID %} 即可,构建速度极快且无需查找冗长的文件路径:
1
2
3
[ 点击查看:MD3 博客主题发布! ]( /posts/transition-announcement/ ) {: .preview }
[ 点击查看:指定的内链文章 ]( /posts/a8c9n3/ ) {: .preview }
效果:
关于频道失而复得与未来展望
频道历经波折终于找回,为了更长远的发展,未来文章将首发于博客,频道将作为订阅推送与讨论区。
article
ZGQ Inc.'s Blog
浏览器隐私争议与自用 Firefox 魔改版推荐
资讯:针对浏览器隐私问题的探讨,并推荐频道主自用的 RunningCheese Firefox 魔改版及实用拓展推荐。
article
ZGQ Inc.'s Blog
外链社交媒体预览 (Open Graph)
对于外链,Jekyll 会在后台智能发起请求,抓取目标网站的 og:title, og:description, og:image 等社交媒体标签,并自动匹配对应域名的 Favicon。
(第一次编译时需要耗费零点几秒抓取外网数据,之后会写入缓存瞬间完成!)
1
[ GitHub - 全球最大的开源社区 ]( https://github.com/ ) {: .preview }
效果:
GitHub · Change is constant. GitHub keeps you ahead. · GitHub
Join the world's most widely adopted, AI-powered developer platform where millions of developers, businesses, and the largest open source community build software that advan...
github.com
艺术与社区深度元数据预览 (Pixiv & e621)
针对 Pixiv 与 e621 平台进行了专门的 Open Graph 与官方元数据 API 增强:
无损自适应缩略图 :采用居中自适应容器(contain),彻底消除强制剪裁,完整保留立绘/插画纵向构图。
卡片宽度升级 :卡片扩展为与流媒体组件一致的大版面(最大宽度 680px),带来更佳的视觉冲击与阅读空间。
精准结构化元数据 :自动抓取并按需展示 原作/版权 (Copyright) 、角色 (Character) 、物种 (Species) 及 多画师 (Artists) ,去除冗长不完整的 General 标签。
R-18 / NSFW 自动遮罩 :自动识别 e621 的 Explicit (rating: e) 分级与 Pixiv 的 xRestrict / R-18 标记,默认施加深度毛玻璃景深高斯模糊与解锁芯片,点击确认即可解锁原图且不触发超链接跳转。
1
2
3
4
5
6
7
8
9
10
11
<!-- 1. 全年龄普通画作(无裁切自适应立绘) -->
[ Pixiv 画作 ]( https://www.pixiv.net/artworks/149691446 ) {: .preview }
<!-- 2. e621 角色/原作/物种结构化元数据与多画师卡片 -->
[ e621 插画 ]( https://e621.net/posts/6234366 ) {: .preview }
<!-- 3. Pixiv R-18 敏感内容自动毛玻璃遮罩 -->
[ Pixiv R-18 画作 ]( https://www.pixiv.net/artworks/149736454 ) {: .preview }
<!-- 4. e621 Explicit (R-18) 自动毛玻璃遮罩 -->
[ e621 R-18 ]( https://e621.net/posts/3605521 ) {: .preview }
效果:
Pixiv Artwork #149691446
image ID: 149691446
View illustration 149691446 on Pixiv
pixiv.net
e621 #6234366 by kitune1tu
verified_user Safepalette kitune1tuthumb_up +27
物种: canid, canine, fox
e621.net
visibility_off
R-18 敏感内容 · 点击显示
Pixiv Artwork #149736454
18_up_rating R-18 (NSFW)image ID: 149736454
Pixiv ID: 149736454 (R-18 敏感内容)
pixiv.net
visibility_off
R-18 敏感内容 · 点击显示
e621 #3605521 by kuromu
18_up_rating R-18 (Explicit)palette kuromuthumb_up +1078
物种: ambiguous species, domestic cat, felid
e621.net
Telegram 实体资料卡片预览 (Channels, Groups, Users & Bots)
针对 Telegram 公开实体链接(频道、群组、个人用户、机器人),支持直接通过 Markdown 超链接追加 {: .preview } 渲染为 MD3 结构化资料卡:
头像与类型标签 :圆形头像与语义化类型 Chip(频道、群组、用户、Bot);
粉丝与成员计数 :自动解析频道订阅人数或群组在线/总人数;
暗色主题兼容 :完美遵循系统明暗主题切换。
1
2
3
4
5
6
7
8
9
10
11
<!-- 1. Telegram 公开频道 -->
[ 𝐙𝐆𝐐 ɪɴᴄ.的唠嗑频道 ]( https://t.me/CopyRightZGQInc ) {: .preview }
<!-- 2. Telegram 讨论群组 -->
[ ZGQ Inc. 聊天室 ]( https://t.me/ZGQinc_chat_room ) {: .preview }
<!-- 3. Telegram 个人用户 -->
[ 𝐙𝐆𝐐 ɪɴᴄ. ]( https://t.me/ZGQinc ) {: .preview }
<!-- 4. Telegram 机器人 -->
[ ZGQ Inc.'s Blog 博客助手 ]( https://t.me/zgqinc_blog_bot ) {: .preview }
效果:
𝐙𝐆𝐐 ɪɴᴄ.的唠嗑频道
campaign 频道
@CopyRightZGQInc
•
个人主页: domain.zgqinc.gq 博客: blog.zgqinc.gq
send
查看频道
ZGQ Inc. s'chat room
groups 群组
@ZGQinc_chat_room
•
You can view and join @ZGQinc_chat_room right away.
send
加入群组
𝐙𝐆𝐐 ɪɴᴄ.
person 用户
@ZGQinc
•
是北极狐 | 无法PM请使用bot @ZGQ_PMbot | @CopyRightZGQInc | domain.zgqinc.gq
send
发起私聊
ZGQ Inc.'s Blog 博客助手
smart_toy Bot
@zgqinc_blog_bot
•
ZGQ Inc. 个人博客官方助手。 博客地址: blog.zgqinc.gq
send
启动 Bot
为了让撰写博文时插入流媒体与第三方社交动态更加轻量优雅,本主题全面支持了 通用 oEmbed 协议智能调度器 ,并针对 6 大主流平台进行了深度样式的 MD3 适配。
21.1 通用 oEmbed 智能调度 (embed.html)
无需记忆繁琐的各平台专属标签,只需使用通用的 embed.html 并传入目标 URL,系统会自动识别平台并调度至最佳嵌入方案:
1
{% include embed.html url="https://www.youtube.com/watch?v=dQw4w9WgXcQ" title="Rick Astley" %}
21.2 六大平台专属嵌入方案
1. YouTube 16:9 响应式播放器
采用标准规范播放域名 youtube.com,自适应 16:9 画幅与 MD3 圆角边框,支持 Telegram 即时预览原生播放:
1
{% include youtube.html url="https://youtube.com/watch?v=wL8DVHuWI7Y" %}
效果:
VIDEO
2. Spotify 音乐播放器
支持单曲 (Track)、专辑 (Album)、歌单 (Playlist) 与播客 (Episode),支持正常模式与紧凑 (Compact) 模式:
1
2
3
{% include spotify.html url="https://open.spotify.com/playlist/2XVgr6bpTDOlhKkaYeADld" compact=true %}
{% include spotify.html url="https://open.spotify.com/track/20M5rBGV7pckSBOqozkx0H" compact=true %}
效果:
3. Telegram 消息与动态嵌入
拥有专用 postMessage 动态高度监听机制,实时同步并撑开容器高度 ,彻底消除内嵌滚动条或上下内容被裁切遮挡的痛点,并深度适配暗色主题 :
1
{% include telegram.html url="https://t.me/CopyRightZGQInc/2061" %}
效果:
lightbulb Tip
语法统一与双重支持 :
平台专属组件 :telegram.html 组件不仅支持公开频道发言内嵌,如果传入实体主页链接(如 t.me/CopyRightZGQInc)也会自动渲染为实体资料卡片;
Markdown 快捷预览 :日常撰写博文时,推荐直接使用第 14 节所示的 [名称](链接){: .preview } 语法(无需手写 Liquid 标签),两者享有完全一致的 Material Design 3 资料卡片样式。
遵循官方 X Publish 标准,自动适配夜间与浅色模式并融入 MD3 居中边距:
1
{% include twitter.html url="https://twitter.com/mfmfcha/status/2077770272200069416" %}
效果:
5. Reddit 社区讨论嵌入
原生支持 Reddit 官方交互组件:
1
{% include reddit.html url="https://www.reddit.com/r/OriAndTheBlindForest/comments/p7dtab/i_made_the_ori_font/" %}
效果:
6. GitHub 仓库卡片与 Gist 代码
支持仓库直观卡片展示以及 Gist 高亮代码嵌入:
1
{% include github.html url="https://github.com/ZGQ-inc/jekyll-blog" description="基于 Material Design 3 的现代响应式 Jekyll 博客主题,支持 Telegram Instant View 2.0 原生渲染。" %}
效果:
在撰写包含剧透、核心剧情画面或敏感内容的文章时,你可以直接在 Markdown 图片语法后添加 {: .blur }、{: .spoiler } 或 {: .nsfw } 属性。
系统会自动为图片赋予 Material Design 3 风格的深度毛玻璃景深模糊遮罩(Backdrop Blur) ,并浮现安全提示卡片与「点击确认显示」按键。读者点击确认后,遮罩将伴随柔和的材质过渡平滑淡出。
语法示例
1
 {: .blur data-reason="剧透警告" }
效果展示
23. Telegram 风格文本动态遮罩 (Telegram Spoiler with Cyber Glitch)
主题原生支持与 Telegram 体验一致的行内文本动态遮罩。采用 ||遮罩文本|| 语法,天然支持防剧透、隐藏机密答案或趣味解密交互。
特性与黑客动效机制
赛博数据损坏遮罩 :未揭示时呈现赛博风格的数据坏块微光噪点与 CRT 扫描线纹理,自适应当前主题色。
全乱码等长置换与逐字恢复 :点击遮罩后触发数据恢复动画。初始阶段呈现 100% 纯乱码波动且字符长度严格恒定,随后自左向右高亮逐字解码还原为真实明文。
零排版抖动与零行距偏移 :动画播放期间行高、行距和后方文本坐标保持绝对静止,绝无任何跳动或排版位移。
双向折叠支持 :点击已解密明文,可再次将其重新折叠隐藏回损坏遮罩状态。
富文本嵌套与安全防护 :遮罩内完整支持粗体、链接等富文本;代码块中的逻辑或运算符(如 ||)严格隔离保护。
语法示例
1
2
3
4
* 剧情剧透防护:故事最后的幕后主使其实是 ||侦探自己的双胞胎弟弟||,他在十年前假死脱身。
* 密码密钥展示:服务器初始管理临时密码为 ||sk-proj-antigravity-994827||,请及时修改。
* 行内零位移测试:在段落中隐藏一段 ||高敏感级机密数据情报||,点击解密时后方文本绝对稳定。
* 富文本复合嵌套:支持在遮罩中嵌套 ||包含 **加粗重点** 与 [ 外部链接 ]( https://telegram.org ) 的复合内容||。
效果展示
剧情剧透防护:故事最后的幕后主使其实是 侦探自己的双胞胎弟弟 ,他在十年前假死脱身。
密码密钥展示:服务器初始管理临时密码为 sk-proj-antigravity-994827 ,请及时修改。
行内零位移测试:在段落中隐藏一段 高敏感级机密数据情报 ,点击解密时后方文本绝对稳定。
富文本复合嵌套:支持在遮罩中嵌套 包含 加粗重点 与 外部链接 的复合内容 。
24. 安全隔离 HTML 运行沙盒 (Isolated HTML Sandbox)
针对文章中需要即时演示 HTML 、CSS 样式或 JavaScript 交互组件的场景,本主题原生构建了 完全独立运行的安全 HTML 运行沙盒 (Sandbox) 。
无需引入外部第三方嵌入平台,直接在 Markdown 中使用 ```[sandbox] 代码块,即可在文章内生成一个功能完备的 Material Design 3 风格运行窗口。
安全防护机制 (Zero-Trust Security)
严格隔离沙盒环境 :基于 HTML5 标准 sandbox="allow-scripts"(严格禁止 allow-same-origin ),沙盒以唯一的 null 域独立执行,彻底免疫 XSS 跨站脚本攻击与注入漏洞 ;
零宿主 DOM 越权 :沙盒内的 JavaScript 绝无可能读取宿主博客的 DOM、Cookie、LocalStorage 或 Token,也无法劫持浏览器父级路由;
CSS 样式强隔离 :沙盒内的 CSS 样式完全封装在独立上下文中,绝不会泄漏或污染文章主体样式;
Referrer 泄露拦截 :沙盒请求策略设置为 no-referrer,全方位守护隐私安全。
配置参数指南
支持在代码块声明行中自由传入窗口尺寸、引用路径与安全策略开关:
参数
说明
示例
默认值
src / url
引用本地页面或外部网页文件路径
src="/playground/demo/index.html"
nil (使用内联代码)
height / h
自定义视口高度(支持 px、vh、%)
height="450px" 或 height=400
380px
width / w
自定义视口宽度(自适应移动端弹性收缩)
width="800px" 或 width="90%"
100%
title
标题栏自定义文本
title="WebGL 粒子动画"
HTML 运行沙盒
jail
目录受限隔离:是否仅限在 playground 文件夹内运行
jail="true" / jail="false"
true (防目录遍历)
cookies
同源权限与 Cookie 读写开关
cookies="true" (开启同源存储权限)
false (严格阻断)
cross_origin
跨域网络请求开关 (CORS / CSP 拦截外部 API)
cross_origin="false" (禁用外部请求)
true (允许外部调用)
cross_path
是否允许跨路径引用非 playground 目录页面
cross_path="true"
false
code / source
是否提供“查看源码”折叠抽屉(对 src 页面自动读取)
code="false"(隐藏抽屉)
true
纯数字简写
仅传入尺寸数字或 px 时,自动映射为高度
```[sandbox 450px]
380px
lightbulb Tip
Liquid 标签支持 :除了 Markdown 代码块外,你还可以直接使用 Liquid 标签嵌入沙盒页面:
{% sandbox src="/playground/demo/index.html" height="480px" title="演示组件" %}
交互操作特性
🔄 实时重置 (Reload / Refresh) :点击右上角刷新按钮,即刻重新初始化沙盒上下文并重置动画和脚本状态;
📝 源码抽屉 (View Source) :内置可折叠的代码面板与一键复制功能,方便读者查看和临摹 HTML 原型;
⛶ 全屏沉浸体验 (Fullscreen) :点击全屏按钮可进入无干扰的全屏独立视界,按 Esc 键随时退出;
↕ 实时高度拖拽拉伸 (Drag Resize) :视口底部配备 MD3 拖动手柄,支持读者按住鼠标上下拖拽自由调节展示高度;
🌓 明暗主题动态感知 :沙盒会自动监听全站主题切换,并通过安全的 postMessage 向沙盒内部发送同步信号。
语法示例
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
``` [sandbox height="360px" title="交互计数器与动效 (Interactive Counter)"]
<div class="card">
<h2>MD3 计数器</h2>
<div id="count">0</div>
<div class="btn-group">
<button onclick="change(-1)">-1</button>
<button onclick="reset()">重置</button>
<button onclick="change(1)">+1</button>
</div>
</div>
<style>
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
font-family: system-ui, -apple-system, sans-serif;
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
color: white;
}
.card {
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.4);
padding: 2rem 3rem;
border-radius: 24px;
text-align: center;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}
h2 { margin: 0 0 0.5rem 0; font-size: 1.25rem; font-weight: 600; }
#count { font-size: 4rem; font-weight: 800; margin: 0.5rem 0 1.25rem 0; }
.btn-group { display: flex; gap: 0.75rem; justify-content: center; }
button {
padding: 0.6rem 1.3rem;
font-size: 1rem;
font-weight: 600;
border-radius: 14px;
border: none;
background: white;
color: #0077b6;
cursor: pointer;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}
button:hover { transform: translateY(-2px) scale(1.04); }
button:active { transform: translateY(0) scale(0.96); }
</style>
<script>
let n = 0;
function change(v) { n += v; update(); }
function reset() { n = 0; update(); }
function update() { document.getElementById("count").textContent = n; }
</script>
```
效果展示
1. 动态 JavaScript 交互组件演示
deployed_code
交互计数器与动效 (Interactive Counter)
verified_user
隔离沙盒
refresh
code
fullscreen
html
HTML 源码
content_copy
复制代码
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
<div class= "card" >
<h2> MD3 计数器</h2>
<div id= "count" class= "count-number" > 0</div>
<div class= "btn-group" >
<button onclick= "change(-1)" > -1</button>
<button onclick= "reset()" > 重置</button>
<button onclick= "change(1)" > +1</button>
</div>
</div>
<style>
body {
display : flex ;
align-items : center ;
justify-content : center ;
min-height : 100vh ;
margin : 0 ;
font-family : system-ui , - apple-system , sans-serif ;
background : linear-gradient ( 135deg , #4facfe 0% , #00f2fe 100% );
color : white ;
}
.card {
background : rgba ( 255 , 255 , 255 , 0.2 );
backdrop-filter : blur ( 16px );
-webkit-backdrop-filter : blur ( 16px );
border : 1px solid rgba ( 255 , 255 , 255 , 0.4 );
padding : 2rem 3rem ;
border-radius : 24px ;
text-align : center ;
box-shadow : 0 10px 30px rgba ( 0 , 0 , 0 , 0.15 );
}
h2 { margin : 0 0 0.5rem 0 ; font-size : 1.25rem ; font-weight : 600 ; }
.count-number { font-size : 4rem ; font-weight : 800 ; margin : 0.5rem 0 1.25rem 0 ; }
.btn-group { display : flex ; gap : 0.75rem ; justify-content : center ; }
button {
padding : 0.6rem 1.3rem ;
font-size : 1rem ;
font-weight : 600 ;
border-radius : 14px ;
border : none ;
background : white ;
color : #0077b6 ;
cursor : pointer ;
box-shadow : 0 4px 12px rgba ( 0 , 0 , 0 , 0.1 );
transition : transform 0.15s cubic-bezier ( 0.4 , 0 , 0.2 , 1 );
}
button :hover { transform : translateY ( -2px ) scale ( 1.04 ); }
button :active { transform : translateY ( 0 ) scale ( 0.96 ); }
</style>
<script>
let n = 0 ;
function change ( v ) { n += v ; update (); }
function reset () { n = 0 ; update (); }
function update () { document . getElementById ( " count " ). textContent = n ; }
</script>
2. 纯 CSS 3D 空间变换效果
deployed_code
CSS 3D 悬浮卡片 (3D Card Effect)
verified_user
隔离沙盒
refresh
code
fullscreen
html
HTML 源码
content_copy
复制代码
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
<div class= "card-3d" >
<div class= "card-content" >
<div class= "badge" > CSS 3D</div>
<h3> Antigravity Blog</h3>
<p> 完全独立的沙盒空间,自由探索 CSS 3D 渲染与动效。</p>
</div>
</div>
<style>
body {
display : flex ;
align-items : center ;
justify-content : center ;
min-height : 100vh ;
margin : 0 ;
perspective : 1000px ;
background : #0f172a ;
font-family : system-ui , sans-serif ;
}
.card-3d {
width : 280px ;
height : 170px ;
border-radius : 20px ;
background : linear-gradient ( 135deg , #6366f1 0% , #a855f7 100% );
box-shadow : 0 20px 40px -15px rgba ( 99 , 102 , 241 , 0.5 );
transition : transform 0.4s cubic-bezier ( 0.4 , 0 , 0.2 , 1 );
transform-style : preserve-3d ;
cursor : pointer ;
display : flex ;
align-items : center ;
justify-content : center ;
padding : 1.5rem ;
box-sizing : border-box ;
color : white ;
}
.card-3d :hover {
transform : rotateX ( 15deg ) rotateY ( -18deg ) translateZ ( 20px );
}
.card-content {
transform : translateZ ( 30px );
text-align : center ;
}
.badge {
display : inline-block ;
padding : 3px 10px ;
background : rgba ( 255 , 255 , 255 , 0.2 );
border-radius : 12px ;
font-size : 0.75rem ;
font-weight : 700 ;
letter-spacing : 0.05em ;
margin-bottom : 0.5rem ;
}
h3 { margin : 0 0 0.5rem 0 ; font-size : 1.3rem ; }
p { margin : 0 ; font-size : 0.85rem ; opacity : 0.9 ; line-height : 1.4 ; }
</style>
3. 引用本地 Playground 独立网页演示 (Local Page Embed)
直接引用博客根目录下的独立网页 /playground/demo/index.html。沙盒自动应用目录受限隔离策略,在顶部提供「在新标签页打开」直达按钮,并自动从文件读取源码填充至「查看源码」抽屉:
deployed_code
Playground 独立网页沙盒 (Local Page Embed)
verified_user
隔离沙盒
folder_managed
受限目录
html
页面源码 (/playground/demo/index.html)
content_copy
复制代码
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<!DOCTYPE html>
<html lang= "zh-CN" >
<head>
<meta charset= "utf-8" >
<meta name= "viewport" content= "width=device-width, initial-scale=1.0" >
<title> Playground Demo - 独立沙盒演示</title>
<style>
:root {
--bg-base : #f8fafc ;
--card-bg : #ffffff ;
--text-main : #0f172a ;
--text-muted : #64748b ;
--border-color : #e2e8f0 ;
--primary : #3b82f6 ;
--primary-hover : #2563eb ;
--primary-light : #eff6ff ;
--accent : #8b5cf6 ;
--success : #10b981 ;
--warning : #f59e0b ;
--danger : #ef4444 ;
--code-bg : #f1f5f9 ;
--shadow : 0 4px 16px -2px rgba ( 15 , 23 , 42 , 0.08 );
}
html [ data-theme = "dark" ] {
--bg-base : #0b0f19 ;
--card-bg : #151d2e ;
--text-main : #f1f5f9 ;
--text-muted : #94a3b8 ;
--border-color : #243048 ;
--primary : #60a5fa ;
--primary-hover : #3b82f6 ;
--primary-light : rgba ( 59 , 130 , 246 , 0.15 );
--accent : #a78bfa ;
--success : #34d399 ;
--warning : #fbbf24 ;
--danger : #f87171 ;
--code-bg : #0d1424 ;
--shadow : 0 4px 20px -2px rgba ( 0 , 0 , 0 , 0.4 );
}
@media ( prefers-color-scheme : dark ) {
html : not ([ data-theme = "light" ]) {
--bg-base : #0b0f19 ;
--card-bg : #151d2e ;
--text-main : #f1f5f9 ;
--text-muted : #94a3b8 ;
--border-color : #243048 ;
--primary : #60a5fa ;
--primary-hover : #3b82f6 ;
--primary-light : rgba ( 59 , 130 , 246 , 0.15 );
--accent : #a78bfa ;
--success : #34d399 ;
--warning : #fbbf24 ;
--danger : #f87171 ;
--code-bg : #0d1424 ;
--shadow : 0 4px 20px -2px rgba ( 0 , 0 , 0 , 0.4 );
}
}
* { box-sizing : border-box ; margin : 0 ; padding : 0 ; }
body {
font-family : - apple-system , BlinkMacSystemFont , "Segoe UI" , Roboto , "Helvetica Neue" , Arial , sans-serif ;
background-color : var ( --bg-base );
color : var ( --text-main );
padding : 1.25rem ;
min-height : 100vh ;
display : flex ;
flex-direction : column ;
gap : 1.25rem ;
transition : background-color 0.25s ease , color 0.25s ease ;
}
.demo-header {
display : flex ;
align-items : center ;
justify-content : space-between ;
flex-wrap : wrap ;
gap : 0.75rem ;
padding-bottom : 0.75rem ;
border-bottom : 1px solid var ( --border-color );
}
.demo-title-group {
display : flex ;
align-items : center ;
gap : 0.6rem ;
}
.demo-logo {
width : 34px ;
height : 34px ;
border-radius : 10px ;
background : linear-gradient ( 135deg , var ( --primary ) 0% , var ( --accent ) 100% );
display : flex ;
align-items : center ;
justify-content : center ;
color : white ;
font-size : 1.15rem ;
font-weight : 700 ;
box-shadow : 0 4px 10px rgba ( 59 , 130 , 246 , 0.3 );
}
.demo-title {
font-size : 1.1rem ;
font-weight : 700 ;
color : var ( --text-main );
}
.demo-badges {
display : flex ;
align-items : center ;
gap : 0.4rem ;
flex-wrap : wrap ;
}
.badge-chip {
font-size : 0.75rem ;
font-weight : 600 ;
padding : 0.2rem 0.55rem ;
border-radius : 999px ;
border : 1px solid var ( --border-color );
background-color : var ( --card-bg );
color : var ( --text-muted );
}
.badge-chip.active {
border-color : var ( --primary );
background-color : var ( --primary-light );
color : var ( --primary );
}
.grid-container {
display : grid ;
grid-template-columns : repeat ( auto-fit , minmax ( 280px , 1fr ));
gap : 1rem ;
}
.card {
background-color : var ( --card-bg );
border : 1px solid var ( --border-color );
border-radius : 16px ;
padding : 1.25rem ;
box-shadow : var ( --shadow );
display : flex ;
flex-direction : column ;
gap : 0.85rem ;
transition : transform 0.2s ease , box-shadow 0.2s ease ;
}
.card :hover {
transform : translateY ( -2px );
box-shadow : 0 8px 24px -4px rgba ( 15 , 23 , 42 , 0.12 );
}
.card-title {
font-size : 0.95rem ;
font-weight : 600 ;
color : var ( --text-main );
display : flex ;
align-items : center ;
gap : 0.4rem ;
}
.card-desc {
font-size : 0.82rem ;
color : var ( --text-muted );
line-height : 1.45 ;
}
.btn-group {
display : flex ;
gap : 0.5rem ;
flex-wrap : wrap ;
}
button {
padding : 0.45rem 0.85rem ;
font-size : 0.82rem ;
font-weight : 600 ;
border-radius : 10px ;
border : 1px solid var ( --border-color );
background-color : var ( --card-bg );
color : var ( --text-main );
cursor : pointer ;
display : inline-flex ;
align-items : center ;
gap : 0.35rem ;
transition : background-color 0.15s , border-color 0.15s , transform 0.15s ;
}
button :hover {
background-color : var ( --primary-light );
border-color : var ( --primary );
color : var ( --primary );
transform : translateY ( -1px );
}
button :active {
transform : translateY ( 0 ) scale ( 0.98 );
}
button .primary {
background-color : var ( --primary );
border-color : var ( --primary );
color : white ;
}
button .primary :hover {
background-color : var ( --primary-hover );
}
.result-terminal {
background-color : var ( --code-bg );
border : 1px solid var ( --border-color );
border-radius : 10px ;
padding : 0.65rem 0.85rem ;
font-family : ui-monospace , SFMono-Regular , Menlo , Monaco , Consolas , monospace ;
font-size : 0.78rem ;
line-height : 1.5 ;
color : var ( --text-main );
min-height : 52px ;
word-break : break-all ;
white-space : pre-wrap ;
}
.status-item {
display : flex ;
justify-content : space-between ;
font-size : 0.8rem ;
padding : 0.3rem 0 ;
border-bottom : 1px dashed var ( --border-color );
}
.status-item :last-child {
border-bottom : none ;
}
.status-label {
color : var ( --text-muted );
}
.status-value {
font-weight : 600 ;
font-family : monospace ;
}
.status-value.safe { color : var ( --success ); }
.status-value.warn { color : var ( --warning ); }
.status-value.danger { color : var ( --danger ); }
/* Canvas visual */
.canvas-wrapper {
position : relative ;
width : 100% ;
height : 180px ;
border-radius : 12px ;
overflow : hidden ;
background : linear-gradient ( 180deg , rgba ( 59 , 130 , 246 , 0.05 ) 0% , rgba ( 139 , 92 , 246 , 0.08 ) 100% );
border : 1px solid var ( --border-color );
}
canvas {
width : 100% ;
height : 100% ;
display : block ;
}
.canvas-overlay {
position : absolute ;
bottom : 8px ;
right : 12px ;
font-size : 0.72rem ;
color : var ( --text-muted );
pointer-events : none ;
}
</style>
</head>
<body>
<!-- Top bar -->
<header class= "demo-header" >
<div class= "demo-title-group" >
<div class= "demo-logo" > ⚡</div>
<div>
<h1 class= "demo-title" > Playground 独立网页沙盒</h1>
<p style= "font-size: 0.75rem; color: var(--text-muted);" > 文件路径:<code> /playground/demo/index.html</code></p>
</div>
</div>
<div class= "demo-badges" >
<span class= "badge-chip active" id= "themeChip" > 🌓 主题: 跟随宿主</span>
<span class= "badge-chip" id= "originChip" > 🌐 Origin: 检测中</span>
</div>
</header>
<!-- Content Grid -->
<main class= "grid-container" >
<!-- Card 1: 权限与环境探针 -->
<section class= "card" >
<h2 class= "card-title" > 🛡️ 沙盒安全策略探针</h2>
<p class= "card-desc" > 自动检测当前 iframe 的沙盒权限级别,验证 Cookie、本地存储与同源策略隔离状态。</p>
<div class= "status-list" >
<div class= "status-item" >
<span class= "status-label" > 执行环境 Origin</span>
<span class= "status-value" id= "originVal" > -</span>
</div>
<div class= "status-item" >
<span class= "status-label" > Cookie 权限状态</span>
<span class= "status-value" id= "cookieStatus" > 待测试</span>
</div>
<div class= "status-item" >
<span class= "status-label" > LocalStorage 权限</span>
<span class= "status-value" id= "storageStatus" > 待测试</span>
</div>
<div class= "status-item" >
<span class= "status-label" > 宿主父级 DOM 访问</span>
<span class= "status-value" id= "parentStatus" > 待测试</span>
</div>
</div>
<div class= "btn-group" >
<button type= "button" class= "primary" onclick= "probeSecurity()" > 一键安全诊断</button>
<button type= "button" onclick= "testWriteCookie()" > 写 Cookie 测试</button>
</div>
<div class= "result-terminal" id= "securityLog" > > 点击上方按键执行沙盒环境探针...</div>
</section>
<!-- Card 2: 跨域与网络请求 -->
<section class= "card" >
<h2 class= "card-title" > 🌐 跨域与网络请求 (CORS / CSP)</h2>
<p class= "card-desc" > 测试当前沙盒配置下向外部域发起异步请求(Fetch API)的连通性与 CSP 策略拦截。</p>
<div class= "btn-group" >
<button type= "button" class= "primary" onclick= "testFetchExternal()" > 测试调用公共 API</button>
<button type= "button" onclick= "testFetchLocal()" > 读取同目录数据</button>
</div>
<div class= "result-terminal" id= "networkLog" > > 等待发起网络请求测试...</div>
</section>
<!-- Card 3: 交互动效画板 -->
<section class= "card" style= "grid-column: 1 / -1;" >
<div style= "display: flex; justify-content: space-between; align-items: center;" >
<h2 class= "card-title" > 🎨 Canvas 粒子动力学演示 (60 FPS)</h2>
<span style= "font-size: 0.75rem; color: var(--text-muted);" > 移动鼠标或点击交互</span>
</div>
<div class= "canvas-wrapper" >
<canvas id= "particleCanvas" ></canvas>
<span class= "canvas-overlay" > Antigravity Interactive Wave</span>
</div>
</section>
</main>
<script>
// 1. Theme Synchronization with Host Window
function applyTheme ( theme ) {
if ( ! theme ) return ;
document . documentElement . setAttribute ( ' data-theme ' , theme );
const chip = document . getElementById ( ' themeChip ' );
if ( chip ) chip . textContent = ' 🌓 主题: ' + ( theme === ' dark ' ? ' 暗色模式 ' : ' 明亮模式 ' );
}
window . addEventListener ( ' message ' , function ( e ) {
if ( e . data && e . data . type === ' theme-change ' ) {
applyTheme ( e . data . theme );
}
});
// Initial theme detection
if ( window . matchMedia && window . matchMedia ( ' (prefers-color-scheme: dark) ' ). matches ) {
applyTheme ( ' dark ' );
}
// 2. Security Probing
function probeSecurity () {
const log = document . getElementById ( ' securityLog ' );
const originVal = document . getElementById ( ' originVal ' );
const cookieStatus = document . getElementById ( ' cookieStatus ' );
const storageStatus = document . getElementById ( ' storageStatus ' );
const parentStatus = document . getElementById ( ' parentStatus ' );
const originChip = document . getElementById ( ' originChip ' );
const isOpaqueOrigin = window . origin === ' null ' || ! window . origin ;
originVal . textContent = window . origin || ' null ' ;
originVal . className = ' status-value ' + ( isOpaqueOrigin ? ' safe ' : ' warn ' );
originChip . textContent = ' 🌐 Origin: ' + ( window . origin || ' null ' );
let messages = [];
messages . push ( ' [环境] window.origin = ' + ( window . origin || ' null ' ));
// Test Cookie Access
let cookieOk = false ;
try {
const testVal = ' test_ ' + Date . now ();
document . cookie = ' sandbox_test= ' + testVal + ' ; path=/; SameSite=Lax ' ;
const readBack = document . cookie ;
cookieOk = readBack . indexOf ( testVal ) !== - 1 ;
cookieStatus . textContent = cookieOk ? ' ✅ 允许读写 ' : ' 🔒 读写拦截 ' ;
cookieStatus . className = ' status-value ' + ( cookieOk ? ' warn ' : ' safe ' );
messages . push ( cookieOk ? ' [Cookie] 成功读取到 Cookie (具备同源权限) ' : ' [Cookie] 无法访问 Cookie (受 sandbox="allow-scripts" 隔离保护) ' );
} catch ( err ) {
cookieStatus . textContent = ' 🔒 严格拦截 ' ;
cookieStatus . className = ' status-value safe ' ;
messages . push ( ' [Cookie] 读写异常拦截: ' + err . message );
}
// Test LocalStorage
try {
localStorage . setItem ( ' __sandbox_test__ ' , ' 1 ' );
localStorage . removeItem ( ' __sandbox_test__ ' );
storageStatus . textContent = ' ✅ 允许存储 ' ;
storageStatus . className = ' status-value warn ' ;
messages . push ( ' [Storage] LocalStorage 读写成功 ' );
} catch ( err ) {
storageStatus . textContent = ' 🔒 严格禁用 ' ;
storageStatus . className = ' status-value safe ' ;
messages . push ( ' [Storage] LocalStorage 被沙盒严格禁用 ' );
}
// Test Parent DOM access
try {
if ( window . parent && window . parent !== window ) {
const testParent = window . parent . document ;
parentStatus . textContent = ' ⚠️ 允许越权 ' ;
parentStatus . className = ' status-value danger ' ;
messages . push ( ' [父级访问] 警告:能直接访问父窗口 DOM! ' );
} else {
parentStatus . textContent = ' 🔒 隔离 ' ;
parentStatus . className = ' status-value safe ' ;
messages . push ( ' [父级访问] 独立顶级视口 ' );
}
} catch ( err ) {
parentStatus . textContent = ' 🔒 跨源阻断 ' ;
parentStatus . className = ' status-value safe ' ;
messages . push ( ' [父级访问] 已被浏览器同源策略阻断 (Cross-Origin Blocked) ' );
}
log . textContent = messages . join ( ' \n ' );
}
function testWriteCookie () {
const log = document . getElementById ( ' securityLog ' );
try {
const key = ' sandbox_key_ ' + Math . floor ( Math . random () * 1000 );
document . cookie = key + ' =active; path=/; SameSite=Lax ' ;
if ( document . cookie . includes ( key )) {
log . textContent = ' > 写入 Cookie 成功: ' + key + ' =active \n > 当前 cookies: ' + document . cookie ;
} else {
log . textContent = ' > 写入操作被浏览器静默拦截(当前环境为 opaque origin "null") ' ;
}
} catch ( e ) {
log . textContent = ' > 写入 Cookie 失败 (SecurityError): ' + e . message ;
}
}
// 3. Network Fetch Testing
function testFetchExternal () {
const log = document . getElementById ( ' networkLog ' );
log . textContent = ' > 正在向外部 API 发起 GET 请求... ' ;
const start = performance . now ();
fetch ( ' https://dummyjson.com/quotes/random ' , { mode : ' cors ' })
. then ( res => res . json ())
. then ( data => {
const elapsed = Math . round ( performance . now () - start );
log . textContent = ' > 跨域请求成功 ( ' + elapsed + ' ms)! \n ' +
' > Quote: " ' + data . quote + ' " \n ' +
' > Author: ' + data . author ;
})
. catch ( err => {
log . textContent = ' > 跨域网络请求失败/被拦截: \n > ' + err . message + ' \n > (如开启了 cross_origin="false",CSP 将直接阻断外部域连接) ' ;
});
}
function testFetchLocal () {
const log = document . getElementById ( ' networkLog ' );
log . textContent = ' > 正在请求同目录数据: /playground/demo/data.json... ' ;
fetch ( ' ./data.json ' )
. then ( res => {
if ( ! res . ok ) throw new Error ( ' HTTP ' + res . status );
return res . json ();
})
. then ( data => {
log . textContent = ' > 同目录数据读取成功! \n ' + JSON . stringify ( data , null , 2 );
})
. catch ( err => {
log . textContent = ' > 读取同目录数据失败: ' + err . message ;
});
}
// 4. Interactive Particle Canvas
const canvas = document . getElementById ( ' particleCanvas ' );
const ctx = canvas . getContext ( ' 2d ' );
let width , height ;
let particles = [];
let mouse = { x : null , y : null , radius : 100 };
function resizeCanvas () {
width = canvas . width = canvas . offsetWidth ;
height = canvas . height = canvas . offsetHeight ;
initParticles ();
}
function initParticles () {
particles = [];
const count = Math . min ( Math . floor (( width * height ) / 3600 ), 80 );
for ( let i = 0 ; i < count ; i ++ ) {
particles . push ({
x : Math . random () * width ,
y : Math . random () * height ,
vx : ( Math . random () - 0.5 ) * 1.2 ,
vy : ( Math . random () - 0.5 ) * 1.2 ,
radius : Math . random () * 2 + 1.5
});
}
}
function animate () {
ctx . clearRect ( 0 , 0 , width , height );
// Draw connections
for ( let i = 0 ; i < particles . length ; i ++ ) {
for ( let j = i + 1 ; j < particles . length ; j ++ ) {
const dx = particles [ i ]. x - particles [ j ]. x ;
const dy = particles [ i ]. y - particles [ j ]. y ;
const dist = Math . sqrt ( dx * dx + dy * dy );
if ( dist < 90 ) {
ctx . beginPath ();
ctx . strokeStyle = `rgba(96, 165, 250, ${ 0.35 * ( 1 - dist / 90 )} )` ;
ctx . lineWidth = 1 ;
ctx . moveTo ( particles [ i ]. x , particles [ i ]. y );
ctx . lineTo ( particles [ j ]. x , particles [ j ]. y );
ctx . stroke ();
}
}
}
// Update & draw particles
const isDark = document . documentElement . getAttribute ( ' data-theme ' ) === ' dark ' ;
const particleColor = isDark ? ' #93c5fd ' : ' #3b82f6 ' ;
for ( let p of particles ) {
p . x += p . vx ;
p . y += p . vy ;
if ( p . x < 0 || p . x > width ) p . vx *= - 1 ;
if ( p . y < 0 || p . y > height ) p . vy *= - 1 ;
// Mouse reaction
if ( mouse . x !== null ) {
const dx = p . x - mouse . x ;
const dy = p . y - mouse . y ;
const dist = Math . sqrt ( dx * dx + dy * dy );
if ( dist < mouse . radius ) {
const angle = Math . atan2 ( dy , dx );
const force = ( mouse . radius - dist ) / mouse . radius ;
p . x += Math . cos ( angle ) * force * 3 ;
p . y += Math . sin ( angle ) * force * 3 ;
}
}
ctx . beginPath ();
ctx . arc ( p . x , p . y , p . radius , 0 , Math . PI * 2 );
ctx . fillStyle = particleColor ;
ctx . fill ();
}
requestAnimationFrame ( animate );
}
window . addEventListener ( ' resize ' , resizeCanvas );
canvas . addEventListener ( ' mousemove ' , ( e ) => {
const rect = canvas . getBoundingClientRect ();
mouse . x = e . clientX - rect . left ;
mouse . y = e . clientY - rect . top ;
});
canvas . addEventListener ( ' mouseleave ' , () => {
mouse . x = null ;
mouse . y = null ;
});
// Auto initialize on load
window . addEventListener ( ' DOMContentLoaded ' , () => {
probeSecurity ();
resizeCanvas ();
requestAnimationFrame ( animate );
});
</script>
</body>
</html>
4. 开启同源权限与 Cookie 读写开关演示 (Cookies & Same-Origin Enabled)
当你的组件需要与博客同域 Cookie、登录凭证或 LocalStorage 协同工作时,可显式配置 cookies="true"。沙盒将在顶部悬浮警告徽标,并在安全探针中允许读写同源 Cookie 与存储:
deployed_code
Playground 演示 (同源 Cookie 已开启)
cookie
Cookie 开启
folder_managed
受限目录
html
页面源码 (/playground/demo/index.html)
content_copy
复制代码
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<!DOCTYPE html>
<html lang= "zh-CN" >
<head>
<meta charset= "utf-8" >
<meta name= "viewport" content= "width=device-width, initial-scale=1.0" >
<title> Playground Demo - 独立沙盒演示</title>
<style>
:root {
--bg-base : #f8fafc ;
--card-bg : #ffffff ;
--text-main : #0f172a ;
--text-muted : #64748b ;
--border-color : #e2e8f0 ;
--primary : #3b82f6 ;
--primary-hover : #2563eb ;
--primary-light : #eff6ff ;
--accent : #8b5cf6 ;
--success : #10b981 ;
--warning : #f59e0b ;
--danger : #ef4444 ;
--code-bg : #f1f5f9 ;
--shadow : 0 4px 16px -2px rgba ( 15 , 23 , 42 , 0.08 );
}
html [ data-theme = "dark" ] {
--bg-base : #0b0f19 ;
--card-bg : #151d2e ;
--text-main : #f1f5f9 ;
--text-muted : #94a3b8 ;
--border-color : #243048 ;
--primary : #60a5fa ;
--primary-hover : #3b82f6 ;
--primary-light : rgba ( 59 , 130 , 246 , 0.15 );
--accent : #a78bfa ;
--success : #34d399 ;
--warning : #fbbf24 ;
--danger : #f87171 ;
--code-bg : #0d1424 ;
--shadow : 0 4px 20px -2px rgba ( 0 , 0 , 0 , 0.4 );
}
@media ( prefers-color-scheme : dark ) {
html : not ([ data-theme = "light" ]) {
--bg-base : #0b0f19 ;
--card-bg : #151d2e ;
--text-main : #f1f5f9 ;
--text-muted : #94a3b8 ;
--border-color : #243048 ;
--primary : #60a5fa ;
--primary-hover : #3b82f6 ;
--primary-light : rgba ( 59 , 130 , 246 , 0.15 );
--accent : #a78bfa ;
--success : #34d399 ;
--warning : #fbbf24 ;
--danger : #f87171 ;
--code-bg : #0d1424 ;
--shadow : 0 4px 20px -2px rgba ( 0 , 0 , 0 , 0.4 );
}
}
* { box-sizing : border-box ; margin : 0 ; padding : 0 ; }
body {
font-family : - apple-system , BlinkMacSystemFont , "Segoe UI" , Roboto , "Helvetica Neue" , Arial , sans-serif ;
background-color : var ( --bg-base );
color : var ( --text-main );
padding : 1.25rem ;
min-height : 100vh ;
display : flex ;
flex-direction : column ;
gap : 1.25rem ;
transition : background-color 0.25s ease , color 0.25s ease ;
}
.demo-header {
display : flex ;
align-items : center ;
justify-content : space-between ;
flex-wrap : wrap ;
gap : 0.75rem ;
padding-bottom : 0.75rem ;
border-bottom : 1px solid var ( --border-color );
}
.demo-title-group {
display : flex ;
align-items : center ;
gap : 0.6rem ;
}
.demo-logo {
width : 34px ;
height : 34px ;
border-radius : 10px ;
background : linear-gradient ( 135deg , var ( --primary ) 0% , var ( --accent ) 100% );
display : flex ;
align-items : center ;
justify-content : center ;
color : white ;
font-size : 1.15rem ;
font-weight : 700 ;
box-shadow : 0 4px 10px rgba ( 59 , 130 , 246 , 0.3 );
}
.demo-title {
font-size : 1.1rem ;
font-weight : 700 ;
color : var ( --text-main );
}
.demo-badges {
display : flex ;
align-items : center ;
gap : 0.4rem ;
flex-wrap : wrap ;
}
.badge-chip {
font-size : 0.75rem ;
font-weight : 600 ;
padding : 0.2rem 0.55rem ;
border-radius : 999px ;
border : 1px solid var ( --border-color );
background-color : var ( --card-bg );
color : var ( --text-muted );
}
.badge-chip.active {
border-color : var ( --primary );
background-color : var ( --primary-light );
color : var ( --primary );
}
.grid-container {
display : grid ;
grid-template-columns : repeat ( auto-fit , minmax ( 280px , 1fr ));
gap : 1rem ;
}
.card {
background-color : var ( --card-bg );
border : 1px solid var ( --border-color );
border-radius : 16px ;
padding : 1.25rem ;
box-shadow : var ( --shadow );
display : flex ;
flex-direction : column ;
gap : 0.85rem ;
transition : transform 0.2s ease , box-shadow 0.2s ease ;
}
.card :hover {
transform : translateY ( -2px );
box-shadow : 0 8px 24px -4px rgba ( 15 , 23 , 42 , 0.12 );
}
.card-title {
font-size : 0.95rem ;
font-weight : 600 ;
color : var ( --text-main );
display : flex ;
align-items : center ;
gap : 0.4rem ;
}
.card-desc {
font-size : 0.82rem ;
color : var ( --text-muted );
line-height : 1.45 ;
}
.btn-group {
display : flex ;
gap : 0.5rem ;
flex-wrap : wrap ;
}
button {
padding : 0.45rem 0.85rem ;
font-size : 0.82rem ;
font-weight : 600 ;
border-radius : 10px ;
border : 1px solid var ( --border-color );
background-color : var ( --card-bg );
color : var ( --text-main );
cursor : pointer ;
display : inline-flex ;
align-items : center ;
gap : 0.35rem ;
transition : background-color 0.15s , border-color 0.15s , transform 0.15s ;
}
button :hover {
background-color : var ( --primary-light );
border-color : var ( --primary );
color : var ( --primary );
transform : translateY ( -1px );
}
button :active {
transform : translateY ( 0 ) scale ( 0.98 );
}
button .primary {
background-color : var ( --primary );
border-color : var ( --primary );
color : white ;
}
button .primary :hover {
background-color : var ( --primary-hover );
}
.result-terminal {
background-color : var ( --code-bg );
border : 1px solid var ( --border-color );
border-radius : 10px ;
padding : 0.65rem 0.85rem ;
font-family : ui-monospace , SFMono-Regular , Menlo , Monaco , Consolas , monospace ;
font-size : 0.78rem ;
line-height : 1.5 ;
color : var ( --text-main );
min-height : 52px ;
word-break : break-all ;
white-space : pre-wrap ;
}
.status-item {
display : flex ;
justify-content : space-between ;
font-size : 0.8rem ;
padding : 0.3rem 0 ;
border-bottom : 1px dashed var ( --border-color );
}
.status-item :last-child {
border-bottom : none ;
}
.status-label {
color : var ( --text-muted );
}
.status-value {
font-weight : 600 ;
font-family : monospace ;
}
.status-value.safe { color : var ( --success ); }
.status-value.warn { color : var ( --warning ); }
.status-value.danger { color : var ( --danger ); }
/* Canvas visual */
.canvas-wrapper {
position : relative ;
width : 100% ;
height : 180px ;
border-radius : 12px ;
overflow : hidden ;
background : linear-gradient ( 180deg , rgba ( 59 , 130 , 246 , 0.05 ) 0% , rgba ( 139 , 92 , 246 , 0.08 ) 100% );
border : 1px solid var ( --border-color );
}
canvas {
width : 100% ;
height : 100% ;
display : block ;
}
.canvas-overlay {
position : absolute ;
bottom : 8px ;
right : 12px ;
font-size : 0.72rem ;
color : var ( --text-muted );
pointer-events : none ;
}
</style>
</head>
<body>
<!-- Top bar -->
<header class= "demo-header" >
<div class= "demo-title-group" >
<div class= "demo-logo" > ⚡</div>
<div>
<h1 class= "demo-title" > Playground 独立网页沙盒</h1>
<p style= "font-size: 0.75rem; color: var(--text-muted);" > 文件路径:<code> /playground/demo/index.html</code></p>
</div>
</div>
<div class= "demo-badges" >
<span class= "badge-chip active" id= "themeChip" > 🌓 主题: 跟随宿主</span>
<span class= "badge-chip" id= "originChip" > 🌐 Origin: 检测中</span>
</div>
</header>
<!-- Content Grid -->
<main class= "grid-container" >
<!-- Card 1: 权限与环境探针 -->
<section class= "card" >
<h2 class= "card-title" > 🛡️ 沙盒安全策略探针</h2>
<p class= "card-desc" > 自动检测当前 iframe 的沙盒权限级别,验证 Cookie、本地存储与同源策略隔离状态。</p>
<div class= "status-list" >
<div class= "status-item" >
<span class= "status-label" > 执行环境 Origin</span>
<span class= "status-value" id= "originVal" > -</span>
</div>
<div class= "status-item" >
<span class= "status-label" > Cookie 权限状态</span>
<span class= "status-value" id= "cookieStatus" > 待测试</span>
</div>
<div class= "status-item" >
<span class= "status-label" > LocalStorage 权限</span>
<span class= "status-value" id= "storageStatus" > 待测试</span>
</div>
<div class= "status-item" >
<span class= "status-label" > 宿主父级 DOM 访问</span>
<span class= "status-value" id= "parentStatus" > 待测试</span>
</div>
</div>
<div class= "btn-group" >
<button type= "button" class= "primary" onclick= "probeSecurity()" > 一键安全诊断</button>
<button type= "button" onclick= "testWriteCookie()" > 写 Cookie 测试</button>
</div>
<div class= "result-terminal" id= "securityLog" > > 点击上方按键执行沙盒环境探针...</div>
</section>
<!-- Card 2: 跨域与网络请求 -->
<section class= "card" >
<h2 class= "card-title" > 🌐 跨域与网络请求 (CORS / CSP)</h2>
<p class= "card-desc" > 测试当前沙盒配置下向外部域发起异步请求(Fetch API)的连通性与 CSP 策略拦截。</p>
<div class= "btn-group" >
<button type= "button" class= "primary" onclick= "testFetchExternal()" > 测试调用公共 API</button>
<button type= "button" onclick= "testFetchLocal()" > 读取同目录数据</button>
</div>
<div class= "result-terminal" id= "networkLog" > > 等待发起网络请求测试...</div>
</section>
<!-- Card 3: 交互动效画板 -->
<section class= "card" style= "grid-column: 1 / -1;" >
<div style= "display: flex; justify-content: space-between; align-items: center;" >
<h2 class= "card-title" > 🎨 Canvas 粒子动力学演示 (60 FPS)</h2>
<span style= "font-size: 0.75rem; color: var(--text-muted);" > 移动鼠标或点击交互</span>
</div>
<div class= "canvas-wrapper" >
<canvas id= "particleCanvas" ></canvas>
<span class= "canvas-overlay" > Antigravity Interactive Wave</span>
</div>
</section>
</main>
<script>
// 1. Theme Synchronization with Host Window
function applyTheme ( theme ) {
if ( ! theme ) return ;
document . documentElement . setAttribute ( ' data-theme ' , theme );
const chip = document . getElementById ( ' themeChip ' );
if ( chip ) chip . textContent = ' 🌓 主题: ' + ( theme === ' dark ' ? ' 暗色模式 ' : ' 明亮模式 ' );
}
window . addEventListener ( ' message ' , function ( e ) {
if ( e . data && e . data . type === ' theme-change ' ) {
applyTheme ( e . data . theme );
}
});
// Initial theme detection
if ( window . matchMedia && window . matchMedia ( ' (prefers-color-scheme: dark) ' ). matches ) {
applyTheme ( ' dark ' );
}
// 2. Security Probing
function probeSecurity () {
const log = document . getElementById ( ' securityLog ' );
const originVal = document . getElementById ( ' originVal ' );
const cookieStatus = document . getElementById ( ' cookieStatus ' );
const storageStatus = document . getElementById ( ' storageStatus ' );
const parentStatus = document . getElementById ( ' parentStatus ' );
const originChip = document . getElementById ( ' originChip ' );
const isOpaqueOrigin = window . origin === ' null ' || ! window . origin ;
originVal . textContent = window . origin || ' null ' ;
originVal . className = ' status-value ' + ( isOpaqueOrigin ? ' safe ' : ' warn ' );
originChip . textContent = ' 🌐 Origin: ' + ( window . origin || ' null ' );
let messages = [];
messages . push ( ' [环境] window.origin = ' + ( window . origin || ' null ' ));
// Test Cookie Access
let cookieOk = false ;
try {
const testVal = ' test_ ' + Date . now ();
document . cookie = ' sandbox_test= ' + testVal + ' ; path=/; SameSite=Lax ' ;
const readBack = document . cookie ;
cookieOk = readBack . indexOf ( testVal ) !== - 1 ;
cookieStatus . textContent = cookieOk ? ' ✅ 允许读写 ' : ' 🔒 读写拦截 ' ;
cookieStatus . className = ' status-value ' + ( cookieOk ? ' warn ' : ' safe ' );
messages . push ( cookieOk ? ' [Cookie] 成功读取到 Cookie (具备同源权限) ' : ' [Cookie] 无法访问 Cookie (受 sandbox="allow-scripts" 隔离保护) ' );
} catch ( err ) {
cookieStatus . textContent = ' 🔒 严格拦截 ' ;
cookieStatus . className = ' status-value safe ' ;
messages . push ( ' [Cookie] 读写异常拦截: ' + err . message );
}
// Test LocalStorage
try {
localStorage . setItem ( ' __sandbox_test__ ' , ' 1 ' );
localStorage . removeItem ( ' __sandbox_test__ ' );
storageStatus . textContent = ' ✅ 允许存储 ' ;
storageStatus . className = ' status-value warn ' ;
messages . push ( ' [Storage] LocalStorage 读写成功 ' );
} catch ( err ) {
storageStatus . textContent = ' 🔒 严格禁用 ' ;
storageStatus . className = ' status-value safe ' ;
messages . push ( ' [Storage] LocalStorage 被沙盒严格禁用 ' );
}
// Test Parent DOM access
try {
if ( window . parent && window . parent !== window ) {
const testParent = window . parent . document ;
parentStatus . textContent = ' ⚠️ 允许越权 ' ;
parentStatus . className = ' status-value danger ' ;
messages . push ( ' [父级访问] 警告:能直接访问父窗口 DOM! ' );
} else {
parentStatus . textContent = ' 🔒 隔离 ' ;
parentStatus . className = ' status-value safe ' ;
messages . push ( ' [父级访问] 独立顶级视口 ' );
}
} catch ( err ) {
parentStatus . textContent = ' 🔒 跨源阻断 ' ;
parentStatus . className = ' status-value safe ' ;
messages . push ( ' [父级访问] 已被浏览器同源策略阻断 (Cross-Origin Blocked) ' );
}
log . textContent = messages . join ( ' \n ' );
}
function testWriteCookie () {
const log = document . getElementById ( ' securityLog ' );
try {
const key = ' sandbox_key_ ' + Math . floor ( Math . random () * 1000 );
document . cookie = key + ' =active; path=/; SameSite=Lax ' ;
if ( document . cookie . includes ( key )) {
log . textContent = ' > 写入 Cookie 成功: ' + key + ' =active \n > 当前 cookies: ' + document . cookie ;
} else {
log . textContent = ' > 写入操作被浏览器静默拦截(当前环境为 opaque origin "null") ' ;
}
} catch ( e ) {
log . textContent = ' > 写入 Cookie 失败 (SecurityError): ' + e . message ;
}
}
// 3. Network Fetch Testing
function testFetchExternal () {
const log = document . getElementById ( ' networkLog ' );
log . textContent = ' > 正在向外部 API 发起 GET 请求... ' ;
const start = performance . now ();
fetch ( ' https://dummyjson.com/quotes/random ' , { mode : ' cors ' })
. then ( res => res . json ())
. then ( data => {
const elapsed = Math . round ( performance . now () - start );
log . textContent = ' > 跨域请求成功 ( ' + elapsed + ' ms)! \n ' +
' > Quote: " ' + data . quote + ' " \n ' +
' > Author: ' + data . author ;
})
. catch ( err => {
log . textContent = ' > 跨域网络请求失败/被拦截: \n > ' + err . message + ' \n > (如开启了 cross_origin="false",CSP 将直接阻断外部域连接) ' ;
});
}
function testFetchLocal () {
const log = document . getElementById ( ' networkLog ' );
log . textContent = ' > 正在请求同目录数据: /playground/demo/data.json... ' ;
fetch ( ' ./data.json ' )
. then ( res => {
if ( ! res . ok ) throw new Error ( ' HTTP ' + res . status );
return res . json ();
})
. then ( data => {
log . textContent = ' > 同目录数据读取成功! \n ' + JSON . stringify ( data , null , 2 );
})
. catch ( err => {
log . textContent = ' > 读取同目录数据失败: ' + err . message ;
});
}
// 4. Interactive Particle Canvas
const canvas = document . getElementById ( ' particleCanvas ' );
const ctx = canvas . getContext ( ' 2d ' );
let width , height ;
let particles = [];
let mouse = { x : null , y : null , radius : 100 };
function resizeCanvas () {
width = canvas . width = canvas . offsetWidth ;
height = canvas . height = canvas . offsetHeight ;
initParticles ();
}
function initParticles () {
particles = [];
const count = Math . min ( Math . floor (( width * height ) / 3600 ), 80 );
for ( let i = 0 ; i < count ; i ++ ) {
particles . push ({
x : Math . random () * width ,
y : Math . random () * height ,
vx : ( Math . random () - 0.5 ) * 1.2 ,
vy : ( Math . random () - 0.5 ) * 1.2 ,
radius : Math . random () * 2 + 1.5
});
}
}
function animate () {
ctx . clearRect ( 0 , 0 , width , height );
// Draw connections
for ( let i = 0 ; i < particles . length ; i ++ ) {
for ( let j = i + 1 ; j < particles . length ; j ++ ) {
const dx = particles [ i ]. x - particles [ j ]. x ;
const dy = particles [ i ]. y - particles [ j ]. y ;
const dist = Math . sqrt ( dx * dx + dy * dy );
if ( dist < 90 ) {
ctx . beginPath ();
ctx . strokeStyle = `rgba(96, 165, 250, ${ 0.35 * ( 1 - dist / 90 )} )` ;
ctx . lineWidth = 1 ;
ctx . moveTo ( particles [ i ]. x , particles [ i ]. y );
ctx . lineTo ( particles [ j ]. x , particles [ j ]. y );
ctx . stroke ();
}
}
}
// Update & draw particles
const isDark = document . documentElement . getAttribute ( ' data-theme ' ) === ' dark ' ;
const particleColor = isDark ? ' #93c5fd ' : ' #3b82f6 ' ;
for ( let p of particles ) {
p . x += p . vx ;
p . y += p . vy ;
if ( p . x < 0 || p . x > width ) p . vx *= - 1 ;
if ( p . y < 0 || p . y > height ) p . vy *= - 1 ;
// Mouse reaction
if ( mouse . x !== null ) {
const dx = p . x - mouse . x ;
const dy = p . y - mouse . y ;
const dist = Math . sqrt ( dx * dx + dy * dy );
if ( dist < mouse . radius ) {
const angle = Math . atan2 ( dy , dx );
const force = ( mouse . radius - dist ) / mouse . radius ;
p . x += Math . cos ( angle ) * force * 3 ;
p . y += Math . sin ( angle ) * force * 3 ;
}
}
ctx . beginPath ();
ctx . arc ( p . x , p . y , p . radius , 0 , Math . PI * 2 );
ctx . fillStyle = particleColor ;
ctx . fill ();
}
requestAnimationFrame ( animate );
}
window . addEventListener ( ' resize ' , resizeCanvas );
canvas . addEventListener ( ' mousemove ' , ( e ) => {
const rect = canvas . getBoundingClientRect ();
mouse . x = e . clientX - rect . left ;
mouse . y = e . clientY - rect . top ;
});
canvas . addEventListener ( ' mouseleave ' , () => {
mouse . x = null ;
mouse . y = null ;
});
// Auto initialize on load
window . addEventListener ( ' DOMContentLoaded ' , () => {
probeSecurity ();
resizeCanvas ();
requestAnimationFrame ( animate );
});
</script>
</body>
</html>
5. 跨域网络拦截模式演示 (CSP Cross-Origin Blocked)
当配置 cross_origin="false" 时,沙盒将注入严格的内容安全策略(CSP),强制阻断向外部域发起跨域网络请求(可在下方组件中点击「测试调用公共 API」验证策略拦截):
deployed_code
Playground 演示 (跨域拦截已启用)
verified_user
隔离沙盒
folder_managed
受限目录
wifi_off
跨域拦截
html
页面源码 (/playground/demo/index.html)
content_copy
复制代码
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<!DOCTYPE html>
<html lang= "zh-CN" >
<head>
<meta charset= "utf-8" >
<meta name= "viewport" content= "width=device-width, initial-scale=1.0" >
<title> Playground Demo - 独立沙盒演示</title>
<style>
:root {
--bg-base : #f8fafc ;
--card-bg : #ffffff ;
--text-main : #0f172a ;
--text-muted : #64748b ;
--border-color : #e2e8f0 ;
--primary : #3b82f6 ;
--primary-hover : #2563eb ;
--primary-light : #eff6ff ;
--accent : #8b5cf6 ;
--success : #10b981 ;
--warning : #f59e0b ;
--danger : #ef4444 ;
--code-bg : #f1f5f9 ;
--shadow : 0 4px 16px -2px rgba ( 15 , 23 , 42 , 0.08 );
}
html [ data-theme = "dark" ] {
--bg-base : #0b0f19 ;
--card-bg : #151d2e ;
--text-main : #f1f5f9 ;
--text-muted : #94a3b8 ;
--border-color : #243048 ;
--primary : #60a5fa ;
--primary-hover : #3b82f6 ;
--primary-light : rgba ( 59 , 130 , 246 , 0.15 );
--accent : #a78bfa ;
--success : #34d399 ;
--warning : #fbbf24 ;
--danger : #f87171 ;
--code-bg : #0d1424 ;
--shadow : 0 4px 20px -2px rgba ( 0 , 0 , 0 , 0.4 );
}
@media ( prefers-color-scheme : dark ) {
html : not ([ data-theme = "light" ]) {
--bg-base : #0b0f19 ;
--card-bg : #151d2e ;
--text-main : #f1f5f9 ;
--text-muted : #94a3b8 ;
--border-color : #243048 ;
--primary : #60a5fa ;
--primary-hover : #3b82f6 ;
--primary-light : rgba ( 59 , 130 , 246 , 0.15 );
--accent : #a78bfa ;
--success : #34d399 ;
--warning : #fbbf24 ;
--danger : #f87171 ;
--code-bg : #0d1424 ;
--shadow : 0 4px 20px -2px rgba ( 0 , 0 , 0 , 0.4 );
}
}
* { box-sizing : border-box ; margin : 0 ; padding : 0 ; }
body {
font-family : - apple-system , BlinkMacSystemFont , "Segoe UI" , Roboto , "Helvetica Neue" , Arial , sans-serif ;
background-color : var ( --bg-base );
color : var ( --text-main );
padding : 1.25rem ;
min-height : 100vh ;
display : flex ;
flex-direction : column ;
gap : 1.25rem ;
transition : background-color 0.25s ease , color 0.25s ease ;
}
.demo-header {
display : flex ;
align-items : center ;
justify-content : space-between ;
flex-wrap : wrap ;
gap : 0.75rem ;
padding-bottom : 0.75rem ;
border-bottom : 1px solid var ( --border-color );
}
.demo-title-group {
display : flex ;
align-items : center ;
gap : 0.6rem ;
}
.demo-logo {
width : 34px ;
height : 34px ;
border-radius : 10px ;
background : linear-gradient ( 135deg , var ( --primary ) 0% , var ( --accent ) 100% );
display : flex ;
align-items : center ;
justify-content : center ;
color : white ;
font-size : 1.15rem ;
font-weight : 700 ;
box-shadow : 0 4px 10px rgba ( 59 , 130 , 246 , 0.3 );
}
.demo-title {
font-size : 1.1rem ;
font-weight : 700 ;
color : var ( --text-main );
}
.demo-badges {
display : flex ;
align-items : center ;
gap : 0.4rem ;
flex-wrap : wrap ;
}
.badge-chip {
font-size : 0.75rem ;
font-weight : 600 ;
padding : 0.2rem 0.55rem ;
border-radius : 999px ;
border : 1px solid var ( --border-color );
background-color : var ( --card-bg );
color : var ( --text-muted );
}
.badge-chip.active {
border-color : var ( --primary );
background-color : var ( --primary-light );
color : var ( --primary );
}
.grid-container {
display : grid ;
grid-template-columns : repeat ( auto-fit , minmax ( 280px , 1fr ));
gap : 1rem ;
}
.card {
background-color : var ( --card-bg );
border : 1px solid var ( --border-color );
border-radius : 16px ;
padding : 1.25rem ;
box-shadow : var ( --shadow );
display : flex ;
flex-direction : column ;
gap : 0.85rem ;
transition : transform 0.2s ease , box-shadow 0.2s ease ;
}
.card :hover {
transform : translateY ( -2px );
box-shadow : 0 8px 24px -4px rgba ( 15 , 23 , 42 , 0.12 );
}
.card-title {
font-size : 0.95rem ;
font-weight : 600 ;
color : var ( --text-main );
display : flex ;
align-items : center ;
gap : 0.4rem ;
}
.card-desc {
font-size : 0.82rem ;
color : var ( --text-muted );
line-height : 1.45 ;
}
.btn-group {
display : flex ;
gap : 0.5rem ;
flex-wrap : wrap ;
}
button {
padding : 0.45rem 0.85rem ;
font-size : 0.82rem ;
font-weight : 600 ;
border-radius : 10px ;
border : 1px solid var ( --border-color );
background-color : var ( --card-bg );
color : var ( --text-main );
cursor : pointer ;
display : inline-flex ;
align-items : center ;
gap : 0.35rem ;
transition : background-color 0.15s , border-color 0.15s , transform 0.15s ;
}
button :hover {
background-color : var ( --primary-light );
border-color : var ( --primary );
color : var ( --primary );
transform : translateY ( -1px );
}
button :active {
transform : translateY ( 0 ) scale ( 0.98 );
}
button .primary {
background-color : var ( --primary );
border-color : var ( --primary );
color : white ;
}
button .primary :hover {
background-color : var ( --primary-hover );
}
.result-terminal {
background-color : var ( --code-bg );
border : 1px solid var ( --border-color );
border-radius : 10px ;
padding : 0.65rem 0.85rem ;
font-family : ui-monospace , SFMono-Regular , Menlo , Monaco , Consolas , monospace ;
font-size : 0.78rem ;
line-height : 1.5 ;
color : var ( --text-main );
min-height : 52px ;
word-break : break-all ;
white-space : pre-wrap ;
}
.status-item {
display : flex ;
justify-content : space-between ;
font-size : 0.8rem ;
padding : 0.3rem 0 ;
border-bottom : 1px dashed var ( --border-color );
}
.status-item :last-child {
border-bottom : none ;
}
.status-label {
color : var ( --text-muted );
}
.status-value {
font-weight : 600 ;
font-family : monospace ;
}
.status-value.safe { color : var ( --success ); }
.status-value.warn { color : var ( --warning ); }
.status-value.danger { color : var ( --danger ); }
/* Canvas visual */
.canvas-wrapper {
position : relative ;
width : 100% ;
height : 180px ;
border-radius : 12px ;
overflow : hidden ;
background : linear-gradient ( 180deg , rgba ( 59 , 130 , 246 , 0.05 ) 0% , rgba ( 139 , 92 , 246 , 0.08 ) 100% );
border : 1px solid var ( --border-color );
}
canvas {
width : 100% ;
height : 100% ;
display : block ;
}
.canvas-overlay {
position : absolute ;
bottom : 8px ;
right : 12px ;
font-size : 0.72rem ;
color : var ( --text-muted );
pointer-events : none ;
}
</style>
</head>
<body>
<!-- Top bar -->
<header class= "demo-header" >
<div class= "demo-title-group" >
<div class= "demo-logo" > ⚡</div>
<div>
<h1 class= "demo-title" > Playground 独立网页沙盒</h1>
<p style= "font-size: 0.75rem; color: var(--text-muted);" > 文件路径:<code> /playground/demo/index.html</code></p>
</div>
</div>
<div class= "demo-badges" >
<span class= "badge-chip active" id= "themeChip" > 🌓 主题: 跟随宿主</span>
<span class= "badge-chip" id= "originChip" > 🌐 Origin: 检测中</span>
</div>
</header>
<!-- Content Grid -->
<main class= "grid-container" >
<!-- Card 1: 权限与环境探针 -->
<section class= "card" >
<h2 class= "card-title" > 🛡️ 沙盒安全策略探针</h2>
<p class= "card-desc" > 自动检测当前 iframe 的沙盒权限级别,验证 Cookie、本地存储与同源策略隔离状态。</p>
<div class= "status-list" >
<div class= "status-item" >
<span class= "status-label" > 执行环境 Origin</span>
<span class= "status-value" id= "originVal" > -</span>
</div>
<div class= "status-item" >
<span class= "status-label" > Cookie 权限状态</span>
<span class= "status-value" id= "cookieStatus" > 待测试</span>
</div>
<div class= "status-item" >
<span class= "status-label" > LocalStorage 权限</span>
<span class= "status-value" id= "storageStatus" > 待测试</span>
</div>
<div class= "status-item" >
<span class= "status-label" > 宿主父级 DOM 访问</span>
<span class= "status-value" id= "parentStatus" > 待测试</span>
</div>
</div>
<div class= "btn-group" >
<button type= "button" class= "primary" onclick= "probeSecurity()" > 一键安全诊断</button>
<button type= "button" onclick= "testWriteCookie()" > 写 Cookie 测试</button>
</div>
<div class= "result-terminal" id= "securityLog" > > 点击上方按键执行沙盒环境探针...</div>
</section>
<!-- Card 2: 跨域与网络请求 -->
<section class= "card" >
<h2 class= "card-title" > 🌐 跨域与网络请求 (CORS / CSP)</h2>
<p class= "card-desc" > 测试当前沙盒配置下向外部域发起异步请求(Fetch API)的连通性与 CSP 策略拦截。</p>
<div class= "btn-group" >
<button type= "button" class= "primary" onclick= "testFetchExternal()" > 测试调用公共 API</button>
<button type= "button" onclick= "testFetchLocal()" > 读取同目录数据</button>
</div>
<div class= "result-terminal" id= "networkLog" > > 等待发起网络请求测试...</div>
</section>
<!-- Card 3: 交互动效画板 -->
<section class= "card" style= "grid-column: 1 / -1;" >
<div style= "display: flex; justify-content: space-between; align-items: center;" >
<h2 class= "card-title" > 🎨 Canvas 粒子动力学演示 (60 FPS)</h2>
<span style= "font-size: 0.75rem; color: var(--text-muted);" > 移动鼠标或点击交互</span>
</div>
<div class= "canvas-wrapper" >
<canvas id= "particleCanvas" ></canvas>
<span class= "canvas-overlay" > Antigravity Interactive Wave</span>
</div>
</section>
</main>
<script>
// 1. Theme Synchronization with Host Window
function applyTheme ( theme ) {
if ( ! theme ) return ;
document . documentElement . setAttribute ( ' data-theme ' , theme );
const chip = document . getElementById ( ' themeChip ' );
if ( chip ) chip . textContent = ' 🌓 主题: ' + ( theme === ' dark ' ? ' 暗色模式 ' : ' 明亮模式 ' );
}
window . addEventListener ( ' message ' , function ( e ) {
if ( e . data && e . data . type === ' theme-change ' ) {
applyTheme ( e . data . theme );
}
});
// Initial theme detection
if ( window . matchMedia && window . matchMedia ( ' (prefers-color-scheme: dark) ' ). matches ) {
applyTheme ( ' dark ' );
}
// 2. Security Probing
function probeSecurity () {
const log = document . getElementById ( ' securityLog ' );
const originVal = document . getElementById ( ' originVal ' );
const cookieStatus = document . getElementById ( ' cookieStatus ' );
const storageStatus = document . getElementById ( ' storageStatus ' );
const parentStatus = document . getElementById ( ' parentStatus ' );
const originChip = document . getElementById ( ' originChip ' );
const isOpaqueOrigin = window . origin === ' null ' || ! window . origin ;
originVal . textContent = window . origin || ' null ' ;
originVal . className = ' status-value ' + ( isOpaqueOrigin ? ' safe ' : ' warn ' );
originChip . textContent = ' 🌐 Origin: ' + ( window . origin || ' null ' );
let messages = [];
messages . push ( ' [环境] window.origin = ' + ( window . origin || ' null ' ));
// Test Cookie Access
let cookieOk = false ;
try {
const testVal = ' test_ ' + Date . now ();
document . cookie = ' sandbox_test= ' + testVal + ' ; path=/; SameSite=Lax ' ;
const readBack = document . cookie ;
cookieOk = readBack . indexOf ( testVal ) !== - 1 ;
cookieStatus . textContent = cookieOk ? ' ✅ 允许读写 ' : ' 🔒 读写拦截 ' ;
cookieStatus . className = ' status-value ' + ( cookieOk ? ' warn ' : ' safe ' );
messages . push ( cookieOk ? ' [Cookie] 成功读取到 Cookie (具备同源权限) ' : ' [Cookie] 无法访问 Cookie (受 sandbox="allow-scripts" 隔离保护) ' );
} catch ( err ) {
cookieStatus . textContent = ' 🔒 严格拦截 ' ;
cookieStatus . className = ' status-value safe ' ;
messages . push ( ' [Cookie] 读写异常拦截: ' + err . message );
}
// Test LocalStorage
try {
localStorage . setItem ( ' __sandbox_test__ ' , ' 1 ' );
localStorage . removeItem ( ' __sandbox_test__ ' );
storageStatus . textContent = ' ✅ 允许存储 ' ;
storageStatus . className = ' status-value warn ' ;
messages . push ( ' [Storage] LocalStorage 读写成功 ' );
} catch ( err ) {
storageStatus . textContent = ' 🔒 严格禁用 ' ;
storageStatus . className = ' status-value safe ' ;
messages . push ( ' [Storage] LocalStorage 被沙盒严格禁用 ' );
}
// Test Parent DOM access
try {
if ( window . parent && window . parent !== window ) {
const testParent = window . parent . document ;
parentStatus . textContent = ' ⚠️ 允许越权 ' ;
parentStatus . className = ' status-value danger ' ;
messages . push ( ' [父级访问] 警告:能直接访问父窗口 DOM! ' );
} else {
parentStatus . textContent = ' 🔒 隔离 ' ;
parentStatus . className = ' status-value safe ' ;
messages . push ( ' [父级访问] 独立顶级视口 ' );
}
} catch ( err ) {
parentStatus . textContent = ' 🔒 跨源阻断 ' ;
parentStatus . className = ' status-value safe ' ;
messages . push ( ' [父级访问] 已被浏览器同源策略阻断 (Cross-Origin Blocked) ' );
}
log . textContent = messages . join ( ' \n ' );
}
function testWriteCookie () {
const log = document . getElementById ( ' securityLog ' );
try {
const key = ' sandbox_key_ ' + Math . floor ( Math . random () * 1000 );
document . cookie = key + ' =active; path=/; SameSite=Lax ' ;
if ( document . cookie . includes ( key )) {
log . textContent = ' > 写入 Cookie 成功: ' + key + ' =active \n > 当前 cookies: ' + document . cookie ;
} else {
log . textContent = ' > 写入操作被浏览器静默拦截(当前环境为 opaque origin "null") ' ;
}
} catch ( e ) {
log . textContent = ' > 写入 Cookie 失败 (SecurityError): ' + e . message ;
}
}
// 3. Network Fetch Testing
function testFetchExternal () {
const log = document . getElementById ( ' networkLog ' );
log . textContent = ' > 正在向外部 API 发起 GET 请求... ' ;
const start = performance . now ();
fetch ( ' https://dummyjson.com/quotes/random ' , { mode : ' cors ' })
. then ( res => res . json ())
. then ( data => {
const elapsed = Math . round ( performance . now () - start );
log . textContent = ' > 跨域请求成功 ( ' + elapsed + ' ms)! \n ' +
' > Quote: " ' + data . quote + ' " \n ' +
' > Author: ' + data . author ;
})
. catch ( err => {
log . textContent = ' > 跨域网络请求失败/被拦截: \n > ' + err . message + ' \n > (如开启了 cross_origin="false",CSP 将直接阻断外部域连接) ' ;
});
}
function testFetchLocal () {
const log = document . getElementById ( ' networkLog ' );
log . textContent = ' > 正在请求同目录数据: /playground/demo/data.json... ' ;
fetch ( ' ./data.json ' )
. then ( res => {
if ( ! res . ok ) throw new Error ( ' HTTP ' + res . status );
return res . json ();
})
. then ( data => {
log . textContent = ' > 同目录数据读取成功! \n ' + JSON . stringify ( data , null , 2 );
})
. catch ( err => {
log . textContent = ' > 读取同目录数据失败: ' + err . message ;
});
}
// 4. Interactive Particle Canvas
const canvas = document . getElementById ( ' particleCanvas ' );
const ctx = canvas . getContext ( ' 2d ' );
let width , height ;
let particles = [];
let mouse = { x : null , y : null , radius : 100 };
function resizeCanvas () {
width = canvas . width = canvas . offsetWidth ;
height = canvas . height = canvas . offsetHeight ;
initParticles ();
}
function initParticles () {
particles = [];
const count = Math . min ( Math . floor (( width * height ) / 3600 ), 80 );
for ( let i = 0 ; i < count ; i ++ ) {
particles . push ({
x : Math . random () * width ,
y : Math . random () * height ,
vx : ( Math . random () - 0.5 ) * 1.2 ,
vy : ( Math . random () - 0.5 ) * 1.2 ,
radius : Math . random () * 2 + 1.5
});
}
}
function animate () {
ctx . clearRect ( 0 , 0 , width , height );
// Draw connections
for ( let i = 0 ; i < particles . length ; i ++ ) {
for ( let j = i + 1 ; j < particles . length ; j ++ ) {
const dx = particles [ i ]. x - particles [ j ]. x ;
const dy = particles [ i ]. y - particles [ j ]. y ;
const dist = Math . sqrt ( dx * dx + dy * dy );
if ( dist < 90 ) {
ctx . beginPath ();
ctx . strokeStyle = `rgba(96, 165, 250, ${ 0.35 * ( 1 - dist / 90 )} )` ;
ctx . lineWidth = 1 ;
ctx . moveTo ( particles [ i ]. x , particles [ i ]. y );
ctx . lineTo ( particles [ j ]. x , particles [ j ]. y );
ctx . stroke ();
}
}
}
// Update & draw particles
const isDark = document . documentElement . getAttribute ( ' data-theme ' ) === ' dark ' ;
const particleColor = isDark ? ' #93c5fd ' : ' #3b82f6 ' ;
for ( let p of particles ) {
p . x += p . vx ;
p . y += p . vy ;
if ( p . x < 0 || p . x > width ) p . vx *= - 1 ;
if ( p . y < 0 || p . y > height ) p . vy *= - 1 ;
// Mouse reaction
if ( mouse . x !== null ) {
const dx = p . x - mouse . x ;
const dy = p . y - mouse . y ;
const dist = Math . sqrt ( dx * dx + dy * dy );
if ( dist < mouse . radius ) {
const angle = Math . atan2 ( dy , dx );
const force = ( mouse . radius - dist ) / mouse . radius ;
p . x += Math . cos ( angle ) * force * 3 ;
p . y += Math . sin ( angle ) * force * 3 ;
}
}
ctx . beginPath ();
ctx . arc ( p . x , p . y , p . radius , 0 , Math . PI * 2 );
ctx . fillStyle = particleColor ;
ctx . fill ();
}
requestAnimationFrame ( animate );
}
window . addEventListener ( ' resize ' , resizeCanvas );
canvas . addEventListener ( ' mousemove ' , ( e ) => {
const rect = canvas . getBoundingClientRect ();
mouse . x = e . clientX - rect . left ;
mouse . y = e . clientY - rect . top ;
});
canvas . addEventListener ( ' mouseleave ' , () => {
mouse . x = null ;
mouse . y = null ;
});
// Auto initialize on load
window . addEventListener ( ' DOMContentLoaded ' , () => {
probeSecurity ();
resizeCanvas ();
requestAnimationFrame ( animate );
});
</script>
</body>
</html>
25. WebAssembly 即时算力与运行代码块 (Python & SQLite WASM Runner)
在撰写算法分析、数据处理、机器学习或 SQL 数据库教程时,让读者能够无需配置本地开发环境、无需安装任何依赖 ,在文章中直接点击「运行」并即时看到结果,能够极大地提升技术文章的互动性与阅读体验。
本主题原生构建了基于 WebAssembly 的轻量级客户端即时运行引擎,基于按需懒加载机制(Lazy Loading),零服务器后端成本,完全在读者的浏览器端沙盒中安全执行。
核心特性
零配置即开即用 :标准 Markdown 代码块声明语言为 python、py、sql 或 sqlite,代码块右上角将自动呈现符合 MD3 规范的「play_arrow 运行」操作按钮;
按需懒加载 (On-Demand Lazy Loading) :初次点击「运行」时才会通过高可用 CDN 异步拉取运行时 WASM 模块,未点击时全站体积与加载速度不受丝毫影响;
MD3 质感控制台 (Console Panel) :
输出面板具备可折叠抽屉交互与清屏按钮;
展示耗时计时器(如 42ms)与状态指示徽标(Running / Success / Error);
Python (Pyodide) :深度捕获 sys.stdout、sys.stderr 与表达式返回值(Return Value),支持变量作用域在同一页面内跨代码块持久共享;
SQLite (SQL.js) :支持标准 ANSI SQL 语句(DDL/DML/DQL),并自动将 SELECT 查询结果转换为支持横向弹性滚动的 MD3 响应式结构化数据表格;
移动端自适应 :控制台面板与表格在窄屏视口下严格约束宽度,绝无溢出抖动。
语法与效果展示
1. Python 算法即时运算 (基于 Pyodide)
点击代码块右上角的「运行」按钮,即可在浏览器端原地编译并执行 Python 代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import math
def sieve_of_eratosthenes ( limit ):
""" 埃拉托斯特尼质数筛法 """
primes = []
is_prime = [ True ] * ( limit + 1 )
for num in range ( 2 , limit + 1 ):
if is_prime [ num ]:
primes . append ( num )
for multiple in range ( num * num , limit + 1 , num ):
is_prime [ multiple ] = False
return primes
limit = 50
result = sieve_of_eratosthenes ( limit )
print ( f " 1 到 { limit } 之间的质数列表: " )
print ( result )
print ( f " 质数总数: { len ( result ) } " )
# 返回值演示
{ " status " : " completed " , " primes_count " : len ( result ), " max_prime " : max ( result )}
2. SQLite 内存关系型数据库即时查询 (基于 SQL.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
-- 创建部门与员工测试表
CREATE TABLE departments (
id INTEGER PRIMARY KEY ,
name TEXT NOT NULL ,
budget REAL
);
CREATE TABLE employees (
id INTEGER PRIMARY KEY ,
name TEXT NOT NULL ,
dept_id INTEGER ,
salary REAL ,
FOREIGN KEY ( dept_id ) REFERENCES departments ( id )
);
-- 插入模拟数据
INSERT INTO departments VALUES ( 1 , '工程研发部' , 1500000 . 0 );
INSERT INTO departments VALUES ( 2 , '产品设计部' , 800000 . 0 );
INSERT INTO departments VALUES ( 3 , '基础设施部' , 1200000 . 0 );
INSERT INTO employees VALUES ( 101 , 'Alice' , 1 , 95000 . 0 );
INSERT INTO employees VALUES ( 102 , 'Bob' , 1 , 88000 . 0 );
INSERT INTO employees VALUES ( 103 , 'Charlie' , 2 , 82000 . 0 );
INSERT INTO employees VALUES ( 104 , 'Diana' , 3 , 91000 . 0 );
INSERT INTO employees VALUES ( 105 , 'Eve' , 1 , 105000 . 0 );
-- 聚合查询:各部门人均薪资与员工数量
SELECT
d . name AS 部门名称 ,
COUNT ( e . id ) AS 员工人数 ,
ROUND ( AVG ( e . salary ), 2 ) AS 平均年薪 ,
ROUND ( MAX ( e . salary ), 2 ) AS 最高薪资
FROM departments d
LEFT JOIN employees e ON d . id = e . dept_id
GROUP BY d . id
ORDER BY 平均年薪 DESC ;
26. 终端会话录屏回放与交互终端 (Asciinema & Mock Terminal)
在编写 Linux 服务器运维、Git 工作流、编译构建或自动化脚本教程时,录制视频文件往往体积过大且不易暂停复制,而单纯张贴静态命令又缺乏流程步骤的动态直观感。
本主题提供了两套互补的终端展示方案:
交互式模拟终端 (Mock Terminal) :纯文本定义,带有打字机动画、CRT 扫描线风格及单步交互;
Asciinema 录屏播放器 :支持播放工业标准的 .cast 终端会话录制文件,全矢量字符缩放且读者可直接划词复制!
方案 A:交互式模拟终端 (terminal / console)
使用 terminal 或 console 代码块,行首使用 $ 标记命令输入,其余行作为输出。
核心交互体验
拟真打字机动效 :伴随闪烁光标模拟人机交互输入延迟;
单步执行与全部展开 :读者可点击「单步」依次推进命令,或点击「全部」一键展开完整日志;
CRT 显像管复古特效 :配备 CRT 扫描线微光纹理切换按键,兼顾极客情怀与现代阅读感;
一键复制与纯净输出 :智能去除 $ 提示符,让读者复制到剪贴板的内容直接可用于生产环境。
语法示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
``` terminal
$ sudo apt-get update && sudo apt-get upgrade -y
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Fetched 110 kB in 1s (105 kB/s)
Reading package lists... Done
$ docker compose up -d --build
[+] Building 2.4s (12/12) FINISHED
[+] Running 3/3
✔ Network web_net Created
✔ Container blog-redis Started
✔ Container blog-app Started
$ curl -I http://localhost:8080/health
HTTP/1.1 200 OK
Content-Type: application/json
X-Response-Time: 1.2ms
{"status":"healthy","uptime":"99.98%"}
```
效果展示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ sudo apt-get update && sudo apt-get upgrade -y
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Fetched 110 kB in 1s (105 kB/s)
Reading package lists... Done
$ docker compose up -d --build
[+] Building 2.4s (12/12) FINISHED
[+] Running 3/3
✔ Network web_net Created
✔ Container blog-redis Started
✔ Container blog-app Started
$ curl -I http://localhost:8080/health
HTTP/1.1 200 OK
Content-Type: application/json
X-Response-Time: 1.2ms
{"status":"healthy","uptime":"99.98%"}
方案 B:Asciinema 录屏播放器 (cast)
如果你使用 Asciinema 录制了真实终端操作,只需在 cast 代码块中写入 .cast 文件的网络地址或本地绝对路径:
1
2
3
``` cast
/assets/casts/install-demo.cast
```
渲染器将自动按需加载 asciinema-player,渲染高帧率全矢量终端,支持进度条拖拽、倍速播放与字符复制。
27. GLSL 片元着色器实时交互画板 (Fragment Shader Canvas)
类似嵌入式的轻量 Shadertoy !在文章中编写 GLSL 片元着色器代码,博客引擎自动将其绑定到全功能 WebGL 画布上,读者不仅能看到实时的流体、光效和分形动画,还能直接在页面上修改参数看实时渲染变化。
核心特性
兼容 Shadertoy 与标准 GLSL 语法 :既支持标准 Shadertoy 的 void mainImage(out vec4 fragColor, in vec2 fragCoord),也支持原生 WebGL 的 void main();
自动注入全局着色器变量 :
iResolution (vec3):画布当前视口像素分辨率;
iTime (float):从初始化到着色器运行的浮点秒级时间;
iTimeDelta (float):前后两帧之间的时间间隔;
iFrame (int):累计渲染帧数;
iMouse (vec4):鼠标或手指在画布上的实时交互坐标与点击状态;
即时代码编辑器抽屉 (Live Code Drawer) :点击顶部「查看/编辑着色器」展开折叠面板,直接在浏览器中调整颜色、周期、振幅并点击「重新编译」,画面即时更新;
节能与视口感知 (Intersection Observer) :当画布滚动出读者可视区域时,自动暂停 WebGL 渲染管线,避免不必要的 GPU 与电池能耗。
语法示例
使用 shader 或 glsl 代码块:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
``` shader
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec2 uv0 = uv;
vec3 finalColor = vec3(0.0);
for (float i = 0.0; i < 3.0; i++) {
uv = fract(uv * 1.5) - 0.5;
float d = length(uv) * exp(-length(uv0));
vec3 col = 0.5 + 0.5 * cos(iTime + uv0.xyx + vec3(0.0, 2.0, 4.0) + i);
d = sin(d * 8.0 + iTime) / 8.0;
d = abs(d);
d = pow(0.01 / d, 1.2);
finalColor += col * d;
}
fragColor = vec4(finalColor, 1.0);
}
```
效果展示
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec2 uv0 = uv;
vec3 finalColor = vec3(0.0);
for (float i = 0.0; i < 3.0; i++) {
uv = fract(uv * 1.5) - 0.5;
float d = length(uv) * exp(-length(uv0));
vec3 col = 0.5 + 0.5 * cos(iTime + uv0.xyx + vec3(0.0, 2.0, 4.0) + i);
d = sin(d * 8.0 + iTime) / 8.0;
d = abs(d);
d = pow(0.01 / d, 1.2);
finalColor += col * d;
}
fragColor = vec4(finalColor, 1.0);
}
28. 双向反向链接与全站知识网络 (Bidirectional Backlinks)
在个人知识库和深度技术博客中,文章之间不应该是一座座孤岛。通过构建互相关联的超链接体系,能够形成知识的闭环网状结构。
本主题原生开发了 Jekyll 编译期反向链接扫描生成器 (_plugins/backlinks.rb)。
工作原理
编译期全图谱扫描 :在 Jekyll 渲染阶段,插件扫描全站所有博文的内容,精准捕获 {% post_id 文章ID %}、{% post_url ... %} 以及形如 /posts/<slug>/ 的站内超链接;
反向索引图自动映射 :自动为被引用的文章追加 post.backlinks 元数据集合;
MD3 双向反向链接卡片 :如果一篇文章被站内其他文章提及或引用,文章底部会自动渲染「提及本文的页面 (Backlinks)」卡片,展示引用该文的文章标题、发布日期、分类与前言摘要,并支持一键顺滑跳转。
29. 行内徽标、图标与外部表情系统 (Inline Badges, Icons & Emojis)
为了满足撰写现代化技术博客时对状态标记、技术栈展示与生动表达的需求,博客系统深度集成了行内徽标 (Badges) 、矢量图标 (Icons) 与外部表情 (Emojis) 三位一体的行内排版资产体系。所有行内元素均经过严格的基线垂直对齐校准(vertical-align),与中英文字符、字号及行高完美贴合,绝不产生行高突变或裁切抖动。
1. 行内 Badge 徽标体系
支持三种主要形式:MD3 原生语义文本胶囊 、Shields.io / Badge.io 外部动态徽标 ,以及 /assets/icons/ 内部本地微标资产 。
A. MD3 原生文本徽标 (Liquid 标签与 Kramdown 属性)
默认主色调:v2.5.0 或 [v2.5.0]{: .inline-badge .badge-primary}
状态语义色:Beta 、check Passed 、warning Critical 、info Docs 、Pro
实心填充模式:verified LTS Release
B. Shields.io 外部动态微徽标
通过 shields 语法生成高对比度矢量徽标,或直接引用任意外部 Badge 网址(自动居中校准):
C. 内部本地徽标资产 (/assets/icons/)
存放于 /assets/icons/ 目录下的 SVG 或图片微标:
官方认证微标:
2. 行内 Icon 图标体系
无缝覆盖 Google Material Symbols 、Simple Icons (全球技术栈与开发生态 Logo) ,以及本地 SVG 资产 。
A. Google Material Symbols 图标
可在正文中自由穿插矢量图标:
Liquid 标签语法:home 首页、edit_note 内容撰写、terminal 终端交互、deployed_code 独立沙盒、palette MD3 主题
Markdown 快捷短代码:settings 系统设置、bolt 闪电构建、code 源码高亮、rocket_launch 持续部署
B. Simple Icons (博客系统核心技术栈 Logo)
集成官方 CDN 矢量渲染,自动精准匹配官方品牌色彩:
Jekyll 静态站点核心: /
Ruby 脚本与扩展生态: /
Sass / SCSS 样式体系: /
Markdown / GFM 排版: /
WebAssembly 原地运行时: /
Python (Pyodide 交互计算): /
SQLite (SQL.js 内存数据库): /
Cloudflare Pages 全球部署: /
GitHub Actions 自动化 CI/CD: /
C. 内部本地图标资产
站点官方标识: 站点官方 Favicon
核心引擎图标: Jekyll 本地矢量资产 (/assets/icons/jekyll.svg)
3. 外部 Emoji 与 GitHub 表情体系
告别单一的系统自带表情,全面支持 GitHub 官方专有表情包 、GitHub 常用表情短代码映射 ,以及 /assets/icons/ 本地表情包 。
A. GitHub 官方特色表情
GitHub 社区专属吉祥物与标志性表情,直接输入短代码或使用标签:
GitHub Octocat 吉祥物(输入 :octocat: 或 {% emoji octocat %})
GitHub Squirrel 准予发布小松鼠(输入 :shipit:)
经典暴走脸(输入 :trollface:)
B. 跨平台通用 Emoji 短代码自动转译
无需手动调出系统输入法,直接输入标准 GitHub Shortcodes:
庆祝与成就: :tada:、 :sparkles:、 :fire:、 :rocket:、 :100:
交互与反馈: :+1:、 :-1:、 :heart:、 :eyes:、 :zap:
状态与开发: :white_check_mark:、 :bug:、 :warning:、 :bulb:、 :coffee:
C. 内部本地表情
存放于 /assets/icons/ 的专属表情: (支持 {% emoji local:doge %})
forum 评论区