8.9 修改代码高亮样式

This commit is contained in:
小赵同学 committed 2024-08-09 09:07:26 +08:00
1 parent 62cac6c7b0
commit 2e11da0d0b
15 files changed
+2414 -2410

No files matched your search

+6 -6
View File
@@ -91,20 +91,20 @@
<p>
<img data-lazy-src="/pics/2021/10/814315235.png" alt="" class="lazyload"></p>
<p>图片显示的代码是我修改之后的,你只需要将</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>return preg_match(&#34;/screenshot\.(jpg|png|gif|bmp|jpeg)/i&#34;,path);
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>return preg_match(&#34;/screenshot\.(jpg|png|gif|bmp|jpeg)/i&#34;,path);
</span></span></code></pre></div><p>改为</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>return preg_match(&#34;/screenshot\.(jpg|png|gif|bmp|jpeg|webp)/i&#34;,path);
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>return preg_match(&#34;/screenshot\.(jpg|png|gif|bmp|jpeg|webp)/i&#34;,path);
</span></span></code></pre></div><p>然后找到</p>
<p>typecho的var/Widget/Abstract/Contents.php</p>
<p>差不多是686行</p>
<p>
<img data-lazy-src="/pics/2021/10/402523352.png" alt="" class="lazyload"></p>
<p>然后将</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>$value[&#39;attachment&#39;]-&gt;isImage = in_array($content[&#39;type&#39;], array(&#39;jpg&#39;, &#39;jpeg&#39;, &#39;gif&#39;, &#39;png&#39;, &#39;tiff&#39;, &#39;bmp&#39;));
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>$value[&#39;attachment&#39;]-&gt;isImage = in_array($content[&#39;type&#39;], array(&#39;jpg&#39;, &#39;jpeg&#39;, &#39;gif&#39;, &#39;png&#39;, &#39;tiff&#39;, &#39;bmp&#39;));
</span></span></code></pre></div><p>改为</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>$value[&#39;attachment&#39;]-&gt;isImage = in_array($content[&#39;type&#39;], array(&#39;jpg&#39;, &#39;jpeg&#39;, &#39;gif&#39;, &#39;png&#39;, &#39;tiff&#39;, &#39;bmp&#39;, &#39;webp&#39;));
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>$value[&#39;attachment&#39;]-&gt;isImage = in_array($content[&#39;type&#39;], array(&#39;jpg&#39;, &#39;jpeg&#39;, &#39;gif&#39;, &#39;png&#39;, &#39;tiff&#39;, &#39;bmp&#39;, &#39;webp&#39;));
</span></span></code></pre></div><p>然后找到var/Typecho/Common.php,差不多是1399行,我们这里多加一行代码</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&#39;webp&#39; =&gt; &#39;image/webp&#39;,
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&#39;webp&#39; =&gt; &#39;image/webp&#39;,
</span></span></code></pre></div><p>然后去typecho的后台,找到设置-基本,这个地方在其他文件加入webp,然后博客就可以完美支持webp格式图片了</p>
<p>
<img data-lazy-src="/pics/2021/10/46607755.png" alt="" class="lazyload"></p>
@@ -154,7 +154,7 @@ https://squoosh.app</a></p>
<h2 id="让wordpress支持webp格式图片">让WordPress支持webp格式图片</h2>
<p>因为我之前使用的博客系统是WordPress,当然也有让WordPress支持webp格式图片的方法</p>
<p>直接在自己的主题文件的function.php里面加入下面代码即可完美支持webp格式图片</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>//下方一段为webp格式图片支持代码 function bzg_filter_mime_types( $array ) { $array[&#39;webp&#39;] = &#39;image/webp&#39;; return $array; } add_filter( &#39;mime_types&#39;, &#39;bzg_filter_mime_types&#39;, 10, 1 );
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>//下方一段为webp格式图片支持代码 function bzg_filter_mime_types( $array ) { $array[&#39;webp&#39;] = &#39;image/webp&#39;; return $array; } add_filter( &#39;mime_types&#39;, &#39;bzg_filter_mime_types&#39;, 10, 1 );
</span></span><span style="display:flex;"><span>//下方为webp格式图片在媒体库预览图像支持代码 function bzg_file_is_displayable_image($result, $path) { $info = @getimagesize( $path ); if($info[&#39;mime&#39;] == &#39;image/webp&#39;) { $result = true; } return $result; } add_filter( &#39;file_is_displayable_image&#39;, &#39;bzg_file_is_displayable_image&#39;, 10, 2 );
</span></span></code></pre></div><p>基本上就分享这么多,晚安,我的朋友们</p>