<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>B站 on 电商笔记</title><link>https://a19dc1e7.blog-hugo-2f2.pages.dev/tags/b%E7%AB%99/</link><description>Recent content in B站 on 电商笔记</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Thu, 10 Sep 2026 22:30:00 +0800</lastBuildDate><atom:link href="https://a19dc1e7.blog-hugo-2f2.pages.dev/tags/b%E7%AB%99/index.xml" rel="self" type="application/rss+xml"/><item><title>在文章里嵌入 B站视频</title><link>https://a19dc1e7.blog-hugo-2f2.pages.dev/posts/bilibili-video-guide/</link><pubDate>Thu, 10 Sep 2026 22:30:00 +0800</pubDate><guid>https://a19dc1e7.blog-hugo-2f2.pages.dev/posts/bilibili-video-guide/</guid><description>一行短代码把 B站视频放进文章，支持分P、弹幕开关、自定义比例，手机上自适应不变形。</description><content:encoded><![CDATA[<p>B站官方的嵌入代码又长又难记，这个站点配了一个短代码，一行就够了。</p>
<h2 id="最快用法">最快用法</h2>
<p>把下面这行写进 Markdown（<code>BV</code> 号换成你自己的）：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-markdown" data-lang="markdown"><span class="line"><span class="cl">{{&lt; bilibili BV1GJ411x7h7 &gt;}}
</span></span></code></pre></div><p>渲染出来是这样：</p>
<div class="bili-embed" style="position:relative;width:100%;height:0;padding-top:56.25000%;margin:1.75em 0;border-radius:8px;overflow:hidden;background:#000;">
  <iframe src="https://player.bilibili.com/player.html?bvid=BV1GJ411x7h7&amp;page=1&amp;danmaku=0&amp;autoplay=0&amp;muted=0&amp;high_quality=1&amp;as_wide=1" title="Never Gonna Give You Up" loading="lazy" scrolling="no" frameborder="0"
    allowfullscreen="true" allow="autoplay; fullscreen; picture-in-picture"
    style="position:absolute;inset:0;width:100%;height:100%;border:0;"></iframe>
</div>

<p>BV 号在视频页地址栏里，形如 <code>https://www.bilibili.com/video/BV1GJ411x7h7/</code>，
也可以直接写 av 号：<code>{{&lt; bilibili av170001 &gt;}}</code>。</p>
<blockquote>
<p>⚠️ 位置写法只能单独用。一旦要带其它参数，就必须写成 <code>id=&quot;BV...&quot;</code> —— 这是 Hugo 的规则，不允许位置参数和命名参数混用。</p>
</blockquote>
<h2 id="参数">参数</h2>
<table>
	<thead>
			<tr>
					<th>参数</th>
					<th>说明</th>
					<th>默认值</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>id</code></td>
					<td>BV 号或 av 号，也可以直接写在第一个位置</td>
					<td>必填</td>
			</tr>
			<tr>
					<td><code>page</code></td>
					<td>分P，第几个 P</td>
					<td><code>1</code></td>
			</tr>
			<tr>
					<td><code>danmaku</code></td>
					<td>弹幕开关，<code>1</code> 开 <code>0</code> 关</td>
					<td><code>0</code></td>
			</tr>
			<tr>
					<td><code>autoplay</code></td>
					<td>自动播放，<code>1</code> 开</td>
					<td><code>0</code></td>
			</tr>
			<tr>
					<td><code>muted</code></td>
					<td>静音，默认跟随 <code>autoplay</code></td>
					<td>自动</td>
			</tr>
			<tr>
					<td><code>ratio</code></td>
					<td>画面比例</td>
					<td><code>16/9</code></td>
			</tr>
			<tr>
					<td><code>title</code></td>
					<td>iframe 的无障碍标题</td>
					<td><code>哔哩哔哩视频</code></td>
			</tr>
	</tbody>
</table>
<p>几个组合（下面是<strong>示例代码，不会真的插入视频</strong>）：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-markdown" data-lang="markdown"><span class="line"><span class="cl">{{&lt; bilibili id=&#34;BV1GJ411x7h7&#34; page=2 &gt;}}
</span></span><span class="line"><span class="cl">{{&lt; bilibili id=&#34;BV1GJ411x7h7&#34; danmaku=1 autoplay=1 muted=1 &gt;}}
</span></span><span class="line"><span class="cl">{{&lt; bilibili id=&#34;BV1GJ411x7h7&#34; ratio=&#34;4/3&#34; title=&#34;课程讲解&#34; &gt;}}
</span></span></code></pre></div><p>想开弹幕看看实际效果：</p>
<div class="bili-embed" style="position:relative;width:100%;height:0;padding-top:56.25000%;margin:1.75em 0;border-radius:8px;overflow:hidden;background:#000;">
  <iframe src="https://player.bilibili.com/player.html?bvid=BV1GJ411x7h7&amp;page=1&amp;danmaku=1&amp;autoplay=0&amp;muted=0&amp;high_quality=1&amp;as_wide=1" title="开了弹幕的版本" loading="lazy" scrolling="no" frameborder="0"
    allowfullscreen="true" allow="autoplay; fullscreen; picture-in-picture"
    style="position:absolute;inset:0;width:100%;height:100%;border:0;"></iframe>
</div>

<h2 id="写文档时的一个坑">写文档时的一个坑</h2>
<p>Hugo 对<strong>代码块里的 shortcode 也会执行</strong>，所以上面那些示例必须写成转义形式，
否则会真的插进去一个播放器：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-markdown" data-lang="markdown"><span class="line"><span class="cl">{{&lt; bilibili BV1xx &gt;}}
</span></span></code></pre></div><p>看到的那对 <code>/* */</code> 就是转义标记，页面上会显示成正常的短代码写法，方便复制。</p>
<h2 id="几个必须知道的点">几个必须知道的点</h2>
<ol>
<li><strong>未登录访客大概率只能看 360P / 480P</strong>。这是 B站对嵌入播放器的限制，不是配置错了。想要高清得在 B站点登录账号，但访客看不到你的登录态。</li>
<li><strong>播放器右上角会有&quot;去B站看&quot;和推荐浮层</strong>，官方嵌入代码去不掉。</li>
<li><strong><code>autoplay</code> 在手机上基本会被浏览器拦掉</strong>，这是浏览器的自动播放策略，不是代码问题。</li>
<li>视频<strong>必须用 https 播放器地址</strong>，本站已经写死了 <code>https://</code>，不要手动改成 <code>//</code> 或 <code>http</code>，否则在 https 站点上会被浏览器拦成混合内容，白屏。</li>
</ol>
<h2 id="如果-shortcode-不好使">如果 shortcode 不好使</h2>
<p>也可以用主题自带的 <code>rawhtml</code> 短代码直接贴官方嵌入代码：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-markdown" data-lang="markdown"><span class="line"><span class="cl">{{&lt; rawhtml &gt;}}
</span></span><span class="line"><span class="cl">&lt;iframe src=&#34;https://player.bilibili.com/player.html?bvid=BV1GJ411x7h7&amp;page=1&amp;high_quality=1&amp;danmaku=0&#34;
</span></span><span class="line"><span class="cl">        width=&#34;100%&#34; height=&#34;500&#34; scrolling=&#34;no&#34; frameborder=&#34;0&#34; allowfullscreen=&#34;true&#34;&gt;&lt;/iframe&gt;
</span></span><span class="line"><span class="cl">{{&lt; /rawhtml &gt;}}
</span></span></code></pre></div><p>这样写不会有自适应比例，手机上可能变形，所以还是推荐上面的 <code>bilibili</code> 短代码。</p>
]]></content:encoded></item></channel></rss>