mycpen-blog 0.0.0-ejbnwsbmci → 0.0.0-ejbsvibmdm
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index.css +1 -1
- package/js/custom.js +1 -1
- package/js/fcircle.js +1 -1
- package/js/home_page_swiper.js +1 -1
- package/js/people.js +1 -1
- package/js/random.js +1 -1
- package/js/tianli_gpt.js +1 -1
- package/json/friend.json +1 -1
- package/json/link.json +1 -1
- package/manifest.json +1 -1
- package/music1/main.css +1 -1
- package/music1/manifest.json +2 -2
- package/package.json +1 -1
- package/search.xml +5 -5
- package/sitemap.xml +88 -88
- package/wechatOA/main.css +1 -1
package/search.xml
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
<link href="/posts/8d01af11.html"/>
|
9
9
|
<url>/posts/8d01af11.html</url>
|
10
10
|
|
11
|
-
<content type="html"><![CDATA[<h2 id="前言">前言<a class="header-anchor" href="#前言"></a></h2><p>将博客静态文件上传至 github,通过 github action 自动发包至 npm,使用 <a href="https://npmmirror.com/">npmmirror</a> cdn</p><h2 id="npm-命令">npm 命令<a class="header-anchor" href="#npm-命令"></a></h2><p>网址: <a href="https://www.npmjs.com/">https://www.npmjs.com/</a></p><p><strong>切换源</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># https://blog.anheyu.com/posts/sdxhu.html#npm-镜像</span></span><br><span class="line"></span><br><span class="line">npm config <span class="built_in">set</span> registry http://registry.npmmirror.com</span><br><span class="line"><span class="comment"># 切回源</span></span><br><span class="line">npm config <span class="built_in">set</span> registry https://registry.npmjs.org/</span><br></pre></td></tr></table></figure><p><strong>添加本地 npm 用户</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 仅第一次使用需要添加用户,之后会提示你输入你的npm账号密码以及注册邮箱</span></span><br><span class="line">npm adduser</span><br><span class="line"><span class="comment"># 非第一次使用直接登录即可,之后会提示你输入你的npm账号密码以及注册邮箱</span></span><br><span class="line">npm login</span><br></pre></td></tr></table></figure><p><strong>初始化</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm init</span><br></pre></td></tr></table></figure><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fyunetadxq/image/202403242339716.jpg" alt="image-20240324233905199" style="zoom: 50%;" /><p><strong>发布</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm publish</span><br></pre></td></tr></table></figure><p><strong>生成 npm token</strong></p><p>npm 官网 => 头像 => Access Tokens => Generate New Token => 勾选 Automation</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fyunetadxq/image/202403242343688.jpg" alt="image-20240324234307284" style="zoom: 33%;" /><p>github 仓库新增 <code>NPM_TOKEN</code> 的 secrets</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fyunetadxq/image/202403250021463.jpg" alt="image-20240325002106180" style="zoom: 25%;" /><h2 id="示例">示例<a class="header-anchor" href="#示例"></a></h2><h3 id="package-json">package.json<a class="header-anchor" href="#package-json"></a></h3><p><code>scripts/generate_package_json.js</code>,生成 public/package.json</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 生成 public/.package.json</span></span><br><span class="line"><span class="comment">// https://blog.anheyu.com/posts/72ea.html</span></span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">generator</span>.<span class="title function_">register</span>(<span class="string">'npmpackagejson'</span>, <span class="keyword">function</span>(<span class="params">locals</span>){</span><br><span class="line"><span class="comment">// Object</span></span><br><span class="line"><span class="keyword">return</span> {</span><br><span class="line"><span class="attr">path</span>: <span class="string">'/package.json'</span>,</span><br><span class="line"><span class="attr">data</span>: <span class="string">`{</span></span><br><span class="line"><span class="string"> "name": "mycpen-blog",</span></span><br><span class="line"><span class="string"> "version": "0.0.0",</span></span><br><span class="line"><span class="string"> "description": "mycpen blog static file",</span></span><br><span class="line"><span class="string"> "main": "index.js",</span></span><br><span class="line"><span class="string"> "directories": {</span></span><br><span class="line"><span class="string"> "lib": "lib"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "scripts": {</span></span><br><span class="line"><span class="string"> "test": "echo \\"Error: no test specified\\" && exit 1"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "repository": {</span></span><br><span class="line"><span class="string"> "type": "git",</span></span><br><span class="line"><span class="string"> "url": "git+https://github.com/mycpen/blog.git"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "author": "mycpen",</span></span><br><span class="line"><span class="string"> "license": "ISC",</span></span><br><span class="line"><span class="string"> "bugs": {</span></span><br><span class="line"><span class="string"> "url": "https://github.com/mycpen/blog/issues"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "homepage": "https://github.com/mycpen/blog#readme"</span></span><br><span class="line"><span class="string">}</span></span><br><span class="line"><span class="string">`</span>};</span><br><span class="line">});</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="npm-push">npm push<a class="header-anchor" href="#npm-push"></a></h3><p><code>scripts/npmpublish.js</code>,生成 public/.github/workflows/autopublish.yml</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 生成 public/.github/workflows/autopublish.yml</span></span><br><span class="line"><span class="comment">// 推送静态资源至 npm</span></span><br><span class="line"><span class="comment">// https://akilar.top/posts/e82444a6/#具体操作步骤</span></span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">generator</span>.<span class="title function_">register</span>(<span class="string">'npmpush'</span>, <span class="keyword">function</span>(<span class="params">locals</span>){</span><br><span class="line"> <span class="comment">// Object</span></span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="attr">path</span>: <span class="string">'/.github/workflows/autopublish.yml'</span>,</span><br><span class="line"> <span class="attr">data</span>: <span class="string">`name: Node.js Package</span></span><br><span class="line"><span class="string"># 监测分支,2020年10月后github新建仓库默认分支改为main,记得更改</span></span><br><span class="line"><span class="string">on:</span></span><br><span class="line"><span class="string"> push:</span></span><br><span class="line"><span class="string"> branches:</span></span><br><span class="line"><span class="string"> - main</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">jobs:</span></span><br><span class="line"><span class="string"> publish-npm:</span></span><br><span class="line"><span class="string"> runs-on: ubuntu-latest</span></span><br><span class="line"><span class="string"> steps:</span></span><br><span class="line"><span class="string"> - uses: actions/checkout@v2</span></span><br><span class="line"><span class="string"> - uses: actions/setup-node@v1</span></span><br><span class="line"><span class="string"> with:</span></span><br><span class="line"><span class="string"> node-version: "18.x"</span></span><br><span class="line"><span class="string"> registry-url: https://registry.npmjs.org/</span></span><br><span class="line"><span class="string"> - run: npm publish</span></span><br><span class="line"><span class="string"> env:</span></span><br><span class="line"><span class="string"> NODE_AUTH_TOKEN: `</span>+ <span class="string">'${{secrets.npm_token}}'</span> + <span class="string">`</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> - name: Wait for 3 minutes</span></span><br><span class="line"><span class="string"> run: sleep 180 # 等待 3 分钟,单位为秒</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> - name: Sync package from npm to npmmirror</span></span><br><span class="line"><span class="string"> run: |</span></span><br><span class="line"><span class="string"> npm install -g cnpm --registry=https://registry.npmmirror.com</span></span><br><span class="line"><span class="string"> cnpm sync mycpen-blog</span></span><br><span class="line"><span class="string">`</span></span><br><span class="line">};</span><br><span class="line">});</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="npmignore">.npmignore<a class="header-anchor" href="#npmignore"></a></h3><p><code>scripts/npmignore.js</code>,生成 public/.npmignore。目的 不提交 .html 这类文件至 npm</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 生成 public/.npmignore</span></span><br><span class="line"><span class="comment">// https://akilar.top/posts/e82444a6/</span></span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">generator</span>.<span class="title function_">register</span>(<span class="string">'npmignore'</span>, <span class="keyword">function</span>(<span class="params">locals</span>){</span><br><span class="line"><span class="comment">// Object</span></span><br><span class="line"><span class="keyword">return</span> {</span><br><span class="line"><span class="attr">path</span>: <span class="string">'/.npmignore'</span>,</span><br><span class="line"><span class="attr">data</span>: <span class="string">`**/*.html</span></span><br><span class="line"><span class="string">.github/</span></span><br><span class="line"><span class="string">download/</span></span><br><span class="line"><span class="string">ads.txt</span></span><br><span class="line"><span class="string">CNAME</span></span><br><span class="line"><span class="string">robots.txt</span></span><br><span class="line"><span class="string">`</span>};</span><br><span class="line">});</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="change-version">change version<a class="header-anchor" href="#change-version"></a></h3><p><code>.github/replace-localfile-url.py</code>,修改 public/package.json version</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 源码参考 https://blog.csdn.net/qq_38150250/article/details/118026219</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"><span class="keyword">from</span> datetime <span class="keyword">import</span> datetime</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"></span><br><span class="line"><span class="comment"># 文件查找 find . -name file_name -type f</span></span><br><span class="line"><span class="comment"># 查找函数:search_path 查找根路径 </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取文章路径</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">search</span>(<span class="params">search_path, search_result, search_fileType_list</span>):</span><br><span class="line"> <span class="comment"># 获取当前路径下地所有文件</span></span><br><span class="line"> all_file = os.listdir(search_path)</span><br><span class="line"> <span class="comment"># 对于每一个文件</span></span><br><span class="line"> <span class="keyword">for</span> each_file <span class="keyword">in</span> all_file:</span><br><span class="line"> <span class="comment"># 若文件为一个文件夹</span></span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(search_path + each_file):</span><br><span class="line"> <span class="comment"># 递归查找</span></span><br><span class="line"> search(search_path + each_file + <span class="string">'/'</span>, search_result, search_fileType_list)</span><br><span class="line"> <span class="comment"># 如果是需要被查找的文件</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> search_fileType_list:</span><br><span class="line"> <span class="keyword">if</span> re.findall(<span class="string">f'.*\\<span class="subst">{i}</span>$'</span>, each_file) == [each_file]:</span><br><span class="line"> search_result.append(search_path + each_file)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 sed -i 's/old_str/new_str/'</span></span><br><span class="line"><span class="comment"># 文本替换 replace_file_name 需要替换的文件路径,replace_old_str 要替换的字符,replace_new_str 替换的字符</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">replace</span>(<span class="params">replace_file_name, replace_old_str, replace_new_str</span>):</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"r"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f1: </span><br><span class="line"> content = f1.read()</span><br><span class="line"> f1.close()</span><br><span class="line"> t = content.replace(replace_old_str, replace_new_str)</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"w"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f2:</span><br><span class="line"> f2.write(t)</span><br><span class="line"> f2.close()</span><br><span class="line"></span><br><span class="line"><span class="comment"># ==================================================================</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># npm time version | npm_converted_time</span></span><br><span class="line"><span class="comment"># ------------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># 将数字和字母对应关系定义为字典</span></span><br><span class="line">npm_num_mapping = {</span><br><span class="line"> <span class="string">'0'</span>: [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'u'</span>], <span class="string">'1'</span>: [<span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'v'</span>], <span class="string">'2'</span>: [<span class="string">'e'</span>, <span class="string">'f'</span>, <span class="string">'w'</span>], <span class="string">'3'</span>: [<span class="string">'g'</span>, <span class="string">'h'</span>, <span class="string">'x'</span>],</span><br><span class="line"> <span class="string">'4'</span>: [<span class="string">'i'</span>, <span class="string">'j'</span>, <span class="string">'y'</span>], <span class="string">'5'</span>: [<span class="string">'k'</span>, <span class="string">'l'</span>, <span class="string">'z'</span>], <span class="string">'6'</span>: [<span class="string">'m'</span>, <span class="string">'n'</span>], <span class="string">'7'</span>: [<span class="string">'o'</span>, <span class="string">'p'</span>],</span><br><span class="line"> <span class="string">'8'</span>: [<span class="string">'q'</span>, <span class="string">'r'</span>], <span class="string">'9'</span>: [<span class="string">'s'</span>, <span class="string">'t'</span>]</span><br><span class="line">}</span><br><span class="line"><span class="comment"># 当前时间</span></span><br><span class="line">npm_now = datetime.now()</span><br><span class="line"><span class="comment"># 格式化当前时间为指定格式 2403230741</span></span><br><span class="line">npm_formatted_time = npm_now.strftime(<span class="string">"%y%m%d%H%M"</span>)</span><br><span class="line"><span class="comment"># 数字替换为随机映射字母 ejugfhupjv</span></span><br><span class="line">npm_converted_time = <span class="string">''</span></span><br><span class="line"><span class="keyword">for</span> char <span class="keyword">in</span> npm_formatted_time:</span><br><span class="line"> <span class="keyword">if</span> char.isdigit():</span><br><span class="line"> npm_converted_time += <span class="string">''</span>.join(random.choice(npm_num_mapping[char]) <span class="keyword">if</span> char <span class="keyword">in</span> npm_num_mapping <span class="keyword">else</span> char)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> npm_converted_time += char</span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 package.json 0.0.0</span></span><br><span class="line">result_npmPackageJson = [<span class="string">'./public/package.json'</span>]</span><br><span class="line">old_npmPackageJson_version = <span class="string">'0.0.0'</span></span><br><span class="line">new_npmPackageJson_version = <span class="string">f'0.0.0-<span class="subst">{npm_converted_time}</span>'</span></span><br><span class="line">count = <span class="number">0</span></span><br><span class="line"><span class="comment"># json</span></span><br><span class="line"><span class="keyword">for</span> file_name <span class="keyword">in</span> result_npmPackageJson:</span><br><span class="line"> replace(file_name, old_npmPackageJson_version, new_npmPackageJson_version)</span><br><span class="line"> count += <span class="number">1</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"{} done {}"</span>.<span class="built_in">format</span>(file_name, count))</span><br><span class="line"></span><br></pre></td></tr></table></figure><p><code>.github/workflows/autodeploy.yml</code>,执行上方 py 脚本 <code>- name: Replace localFile URL</code></p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Auto</span> <span class="string">deploy</span></span><br><span class="line"><span class="comment"># 当有改动推送到master分支时,启动Action</span></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line"> <span class="attr">workflow_dispatch:</span></span><br><span class="line"> <span class="attr">push:</span></span><br><span class="line"> <span class="attr">branches:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"> <span class="attr">deploy:</span></span><br><span class="line"> <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line"> <span class="attr">steps:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">检查分支</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/checkout@v2</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">ref:</span> <span class="string">main</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">szenius/set-timezone@v1.0</span> <span class="comment"># 设置执行环境的时区</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">timezoneLinux:</span> <span class="string">"Asia/Shanghai"</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">安装</span> <span class="string">Node</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/setup-node@v1</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">node-version:</span> <span class="string">"18.x"</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">安装</span> <span class="string">Hexo</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> export TZ='Asia/Shanghai'</span></span><br><span class="line"><span class="string"> npm install hexo-cli -g</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">缓存</span> <span class="string">Hexo</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/cache@v1</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">cache</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">node_modules</span></span><br><span class="line"> <span class="attr">key:</span> <span class="string">${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">安装依赖</span></span><br><span class="line"> <span class="attr">if:</span> <span class="string">steps.cache.outputs.cache-hit</span> <span class="type">!=</span> <span class="string">'true'</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> npm install gulp-cli -g #全局安装gulp</span></span><br><span class="line"><span class="string"> npm install --save</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Generate</span> <span class="string">static</span> <span class="string">file</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> hexo clean ; hexo generate ; gulp</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Set</span> <span class="string">up</span> <span class="string">Python</span> <span class="number">3.10</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/setup-python@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">python-version:</span> <span class="string">"3.10"</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Install</span> <span class="string">dependencies</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> python -m pip install --upgrade pip</span></span><br><span class="line"><span class="string"> pip install requests</span></span><br><span class="line"><span class="string"></span> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Replace</span> <span class="string">imageBed</span> <span class="string">URL</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> python .github/replace-imgbed-url-v2.py</span></span><br><span class="line"><span class="string"></span> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Replace</span> <span class="string">localFile</span> <span class="string">URL</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> python .github/replace-localfile-url.py</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Delete</span> <span class="string">static</span> <span class="string">file</span> <span class="string">repository</span> <span class="string">tags</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> mkdir tmp_mycpen</span></span><br><span class="line"><span class="string"> cd tmp_mycpen</span></span><br><span class="line"><span class="string"> git clone https://github.com/mycpen/blog.git</span></span><br><span class="line"><span class="string"> cd blog</span></span><br><span class="line"><span class="string"> git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" --delete $(git tag -l)</span></span><br><span class="line"><span class="string"> cd ../..</span></span><br><span class="line"><span class="string"> rm -rf tmp_mycpen</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Deploy</span> <span class="string">static</span> <span class="string">file</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> cd ./public</span></span><br><span class="line"><span class="string"> git init</span></span><br><span class="line"><span class="string"> git config --global user.email 'github-actions[bot]@users.noreply.github.com'</span></span><br><span class="line"><span class="string"> git config --global user.name 'github-actions[bot]'</span></span><br><span class="line"><span class="string"> git add .</span></span><br><span class="line"><span class="string"> git commit -m "$(date +'%Y/%m/%d')"</span></span><br><span class="line"><span class="string"> tag_name=$(date +'%y.%m.%d')</span></span><br><span class="line"><span class="string"> git tag $tag_name</span></span><br><span class="line"><span class="string"> git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" $tag_name</span></span><br><span class="line"><span class="string"> git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" master:main</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Purge</span> <span class="string">JSD</span> <span class="string">cache</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> jsd_purge_urls=("https://purge.jsdelivr.net/gh/mycpen/blog/" "https://purge.jsdelivr.net/gh/mycpen/blog@latest/" "https://purge.jsdelivr.net/gh/mycpen/blog@main/")</span></span><br><span class="line"><span class="string"> for url in "${jsd_purge_urls[@]}"; do curl -s $url; done</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">推送百度</span> <span class="string">url</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> hexo deploy</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Delete</span> <span class="string">workflow</span> <span class="string">runs</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">Mattraks/delete-workflow-runs@v2</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">token:</span> <span class="string">${{</span> <span class="string">secrets.GH_TOKEN</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">repository:</span> <span class="string">${{</span> <span class="string">github.repository</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">retain_days:</span> <span class="number">30</span></span><br><span class="line"> <span class="attr">keep_minimum_runs:</span> <span class="number">6</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="参考">参考<a class="header-anchor" href="#参考"></a></h2><ol><li class="lvl-3"><p><a href="https://akilar.top/posts/e82444a6/">akilar | github-action推送博客部署仓库至NPM</a></p></li><li class="lvl-3"><p><a href="https://akilar.top/posts/3e956346/">akilar | npm图床</a></p></li><li class="lvl-3"><p><a href="https://blog.anheyu.com/posts/b228.html">安知鱼 | hexo博客工作流CI</a></p></li><li class="lvl-3"><p><a href="https://blog.anheyu.com/posts/72ea.html">安知鱼 | npm图床</a></p></li><li class="lvl-3"><p><a href="https://www.cnblogs.com/index-html/p/npm-upload.html#%E6%97%A0%E7%8A%B6%E6%80%81">EtherDream | 文件一键上传到 NPM</a></p></li><li class="lvl-3"><p><a href="https://npmmirror.com/">npmmirror | 同步模块 cnpm sync cnpmcore</a></p></li><li class="lvl-3"><p><a href="https://github.com/ChenYFan/CyanBlog/blob/main/prescripts/pkgpublish.js">github | CyanBlog/pkgpublish.js</a></p></li></ol>]]></content>
|
11
|
+
<content type="html"><![CDATA[<h2 id="前言">前言<a class="header-anchor" href="#前言"></a></h2><p>将博客静态文件上传至 github,通过 github action 自动发包至 npm,使用 <a href="https://npmmirror.com/">npmmirror</a> cdn</p><h2 id="npm-命令">npm 命令<a class="header-anchor" href="#npm-命令"></a></h2><p>网址: <a href="https://www.npmjs.com/">https://www.npmjs.com/</a></p><p><strong>切换源</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># https://blog.anheyu.com/posts/sdxhu.html#npm-镜像</span></span><br><span class="line"></span><br><span class="line">npm config <span class="built_in">set</span> registry http://registry.npmmirror.com</span><br><span class="line"><span class="comment"># 切回源</span></span><br><span class="line">npm config <span class="built_in">set</span> registry https://registry.npmjs.org/</span><br></pre></td></tr></table></figure><p><strong>添加本地 npm 用户</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 仅第一次使用需要添加用户,之后会提示你输入你的npm账号密码以及注册邮箱</span></span><br><span class="line">npm adduser</span><br><span class="line"><span class="comment"># 非第一次使用直接登录即可,之后会提示你输入你的npm账号密码以及注册邮箱</span></span><br><span class="line">npm login</span><br></pre></td></tr></table></figure><p><strong>初始化</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm init</span><br></pre></td></tr></table></figure><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/202403242339716.jpg" alt="image-20240324233905199" style="zoom: 50%;" /><p><strong>发布</strong></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm publish</span><br></pre></td></tr></table></figure><p><strong>生成 npm token</strong></p><p>npm 官网 => 头像 => Access Tokens => Generate New Token => 勾选 Automation</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/202403242343688.jpg" alt="image-20240324234307284" style="zoom: 33%;" /><p>github 仓库新增 <code>NPM_TOKEN</code> 的 secrets</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/202403250021463.jpg" alt="image-20240325002106180" style="zoom: 25%;" /><h2 id="示例">示例<a class="header-anchor" href="#示例"></a></h2><h3 id="package-json">package.json<a class="header-anchor" href="#package-json"></a></h3><p><code>scripts/generate_package_json.js</code>,生成 public/package.json</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 生成 public/.package.json</span></span><br><span class="line"><span class="comment">// https://blog.anheyu.com/posts/72ea.html</span></span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">generator</span>.<span class="title function_">register</span>(<span class="string">'npmpackagejson'</span>, <span class="keyword">function</span>(<span class="params">locals</span>){</span><br><span class="line"><span class="comment">// Object</span></span><br><span class="line"><span class="keyword">return</span> {</span><br><span class="line"><span class="attr">path</span>: <span class="string">'/package.json'</span>,</span><br><span class="line"><span class="attr">data</span>: <span class="string">`{</span></span><br><span class="line"><span class="string"> "name": "mycpen-blog",</span></span><br><span class="line"><span class="string"> "version": "0.0.0",</span></span><br><span class="line"><span class="string"> "description": "mycpen blog static file",</span></span><br><span class="line"><span class="string"> "main": "index.js",</span></span><br><span class="line"><span class="string"> "directories": {</span></span><br><span class="line"><span class="string"> "lib": "lib"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "scripts": {</span></span><br><span class="line"><span class="string"> "test": "echo \\"Error: no test specified\\" && exit 1"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "repository": {</span></span><br><span class="line"><span class="string"> "type": "git",</span></span><br><span class="line"><span class="string"> "url": "git+https://github.com/mycpen/blog.git"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "author": "mycpen",</span></span><br><span class="line"><span class="string"> "license": "ISC",</span></span><br><span class="line"><span class="string"> "bugs": {</span></span><br><span class="line"><span class="string"> "url": "https://github.com/mycpen/blog/issues"</span></span><br><span class="line"><span class="string"> },</span></span><br><span class="line"><span class="string"> "homepage": "https://github.com/mycpen/blog#readme"</span></span><br><span class="line"><span class="string">}</span></span><br><span class="line"><span class="string">`</span>};</span><br><span class="line">});</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="npm-push">npm push<a class="header-anchor" href="#npm-push"></a></h3><p><code>scripts/npmpublish.js</code>,生成 public/.github/workflows/autopublish.yml</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 生成 public/.github/workflows/autopublish.yml</span></span><br><span class="line"><span class="comment">// 推送静态资源至 npm</span></span><br><span class="line"><span class="comment">// https://akilar.top/posts/e82444a6/#具体操作步骤</span></span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">generator</span>.<span class="title function_">register</span>(<span class="string">'npmpush'</span>, <span class="keyword">function</span>(<span class="params">locals</span>){</span><br><span class="line"> <span class="comment">// Object</span></span><br><span class="line"> <span class="keyword">return</span> {</span><br><span class="line"> <span class="attr">path</span>: <span class="string">'/.github/workflows/autopublish.yml'</span>,</span><br><span class="line"> <span class="attr">data</span>: <span class="string">`name: Node.js Package</span></span><br><span class="line"><span class="string"># 监测分支,2020年10月后github新建仓库默认分支改为main,记得更改</span></span><br><span class="line"><span class="string">on:</span></span><br><span class="line"><span class="string"> push:</span></span><br><span class="line"><span class="string"> branches:</span></span><br><span class="line"><span class="string"> - main</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">jobs:</span></span><br><span class="line"><span class="string"> publish-npm:</span></span><br><span class="line"><span class="string"> runs-on: ubuntu-latest</span></span><br><span class="line"><span class="string"> steps:</span></span><br><span class="line"><span class="string"> - uses: actions/checkout@v2</span></span><br><span class="line"><span class="string"> - uses: actions/setup-node@v1</span></span><br><span class="line"><span class="string"> with:</span></span><br><span class="line"><span class="string"> node-version: "18.x"</span></span><br><span class="line"><span class="string"> registry-url: https://registry.npmjs.org/</span></span><br><span class="line"><span class="string"> - run: npm publish</span></span><br><span class="line"><span class="string"> env:</span></span><br><span class="line"><span class="string"> NODE_AUTH_TOKEN: `</span>+ <span class="string">'${{secrets.npm_token}}'</span> + <span class="string">`</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> - name: Wait for 3 minutes</span></span><br><span class="line"><span class="string"> run: sleep 180 # 等待 3 分钟,单位为秒</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> - name: Sync package from npm to npmmirror</span></span><br><span class="line"><span class="string"> run: |</span></span><br><span class="line"><span class="string"> npm install -g cnpm --registry=https://registry.npmmirror.com</span></span><br><span class="line"><span class="string"> cnpm sync mycpen-blog</span></span><br><span class="line"><span class="string">`</span></span><br><span class="line">};</span><br><span class="line">});</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="npmignore">.npmignore<a class="header-anchor" href="#npmignore"></a></h3><p><code>scripts/npmignore.js</code>,生成 public/.npmignore。目的 不提交 .html 这类文件至 npm</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 生成 public/.npmignore</span></span><br><span class="line"><span class="comment">// https://akilar.top/posts/e82444a6/</span></span><br><span class="line"></span><br><span class="line">hexo.<span class="property">extend</span>.<span class="property">generator</span>.<span class="title function_">register</span>(<span class="string">'npmignore'</span>, <span class="keyword">function</span>(<span class="params">locals</span>){</span><br><span class="line"><span class="comment">// Object</span></span><br><span class="line"><span class="keyword">return</span> {</span><br><span class="line"><span class="attr">path</span>: <span class="string">'/.npmignore'</span>,</span><br><span class="line"><span class="attr">data</span>: <span class="string">`**/*.html</span></span><br><span class="line"><span class="string">.github/</span></span><br><span class="line"><span class="string">download/</span></span><br><span class="line"><span class="string">ads.txt</span></span><br><span class="line"><span class="string">CNAME</span></span><br><span class="line"><span class="string">robots.txt</span></span><br><span class="line"><span class="string">`</span>};</span><br><span class="line">});</span><br><span class="line"></span><br></pre></td></tr></table></figure><h3 id="change-version">change version<a class="header-anchor" href="#change-version"></a></h3><p><code>.github/replace-localfile-url.py</code>,修改 public/package.json version</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 源码参考 https://blog.csdn.net/qq_38150250/article/details/118026219</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"><span class="keyword">from</span> datetime <span class="keyword">import</span> datetime</span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"></span><br><span class="line"><span class="comment"># 文件查找 find . -name file_name -type f</span></span><br><span class="line"><span class="comment"># 查找函数:search_path 查找根路径 </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取文章路径</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">search</span>(<span class="params">search_path, search_result, search_fileType_list</span>):</span><br><span class="line"> <span class="comment"># 获取当前路径下地所有文件</span></span><br><span class="line"> all_file = os.listdir(search_path)</span><br><span class="line"> <span class="comment"># 对于每一个文件</span></span><br><span class="line"> <span class="keyword">for</span> each_file <span class="keyword">in</span> all_file:</span><br><span class="line"> <span class="comment"># 若文件为一个文件夹</span></span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(search_path + each_file):</span><br><span class="line"> <span class="comment"># 递归查找</span></span><br><span class="line"> search(search_path + each_file + <span class="string">'/'</span>, search_result, search_fileType_list)</span><br><span class="line"> <span class="comment"># 如果是需要被查找的文件</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> search_fileType_list:</span><br><span class="line"> <span class="keyword">if</span> re.findall(<span class="string">f'.*\\<span class="subst">{i}</span>$'</span>, each_file) == [each_file]:</span><br><span class="line"> search_result.append(search_path + each_file)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 sed -i 's/old_str/new_str/'</span></span><br><span class="line"><span class="comment"># 文本替换 replace_file_name 需要替换的文件路径,replace_old_str 要替换的字符,replace_new_str 替换的字符</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">replace</span>(<span class="params">replace_file_name, replace_old_str, replace_new_str</span>):</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"r"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f1: </span><br><span class="line"> content = f1.read()</span><br><span class="line"> f1.close()</span><br><span class="line"> t = content.replace(replace_old_str, replace_new_str)</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"w"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f2:</span><br><span class="line"> f2.write(t)</span><br><span class="line"> f2.close()</span><br><span class="line"></span><br><span class="line"><span class="comment"># ==================================================================</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># npm time version | npm_converted_time</span></span><br><span class="line"><span class="comment"># ------------------------------------------------------------------</span></span><br><span class="line"><span class="comment"># 将数字和字母对应关系定义为字典</span></span><br><span class="line">npm_num_mapping = {</span><br><span class="line"> <span class="string">'0'</span>: [<span class="string">'a'</span>, <span class="string">'b'</span>, <span class="string">'u'</span>], <span class="string">'1'</span>: [<span class="string">'c'</span>, <span class="string">'d'</span>, <span class="string">'v'</span>], <span class="string">'2'</span>: [<span class="string">'e'</span>, <span class="string">'f'</span>, <span class="string">'w'</span>], <span class="string">'3'</span>: [<span class="string">'g'</span>, <span class="string">'h'</span>, <span class="string">'x'</span>],</span><br><span class="line"> <span class="string">'4'</span>: [<span class="string">'i'</span>, <span class="string">'j'</span>, <span class="string">'y'</span>], <span class="string">'5'</span>: [<span class="string">'k'</span>, <span class="string">'l'</span>, <span class="string">'z'</span>], <span class="string">'6'</span>: [<span class="string">'m'</span>, <span class="string">'n'</span>], <span class="string">'7'</span>: [<span class="string">'o'</span>, <span class="string">'p'</span>],</span><br><span class="line"> <span class="string">'8'</span>: [<span class="string">'q'</span>, <span class="string">'r'</span>], <span class="string">'9'</span>: [<span class="string">'s'</span>, <span class="string">'t'</span>]</span><br><span class="line">}</span><br><span class="line"><span class="comment"># 当前时间</span></span><br><span class="line">npm_now = datetime.now()</span><br><span class="line"><span class="comment"># 格式化当前时间为指定格式 2403230741</span></span><br><span class="line">npm_formatted_time = npm_now.strftime(<span class="string">"%y%m%d%H%M"</span>)</span><br><span class="line"><span class="comment"># 数字替换为随机映射字母 ejugfhupjv</span></span><br><span class="line">npm_converted_time = <span class="string">''</span></span><br><span class="line"><span class="keyword">for</span> char <span class="keyword">in</span> npm_formatted_time:</span><br><span class="line"> <span class="keyword">if</span> char.isdigit():</span><br><span class="line"> npm_converted_time += <span class="string">''</span>.join(random.choice(npm_num_mapping[char]) <span class="keyword">if</span> char <span class="keyword">in</span> npm_num_mapping <span class="keyword">else</span> char)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> npm_converted_time += char</span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 package.json 0.0.0</span></span><br><span class="line">result_npmPackageJson = [<span class="string">'./public/package.json'</span>]</span><br><span class="line">old_npmPackageJson_version = <span class="string">'0.0.0'</span></span><br><span class="line">new_npmPackageJson_version = <span class="string">f'0.0.0-<span class="subst">{npm_converted_time}</span>'</span></span><br><span class="line">count = <span class="number">0</span></span><br><span class="line"><span class="comment"># json</span></span><br><span class="line"><span class="keyword">for</span> file_name <span class="keyword">in</span> result_npmPackageJson:</span><br><span class="line"> replace(file_name, old_npmPackageJson_version, new_npmPackageJson_version)</span><br><span class="line"> count += <span class="number">1</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"{} done {}"</span>.<span class="built_in">format</span>(file_name, count))</span><br><span class="line"></span><br></pre></td></tr></table></figure><p><code>.github/workflows/autodeploy.yml</code>,执行上方 py 脚本 <code>- name: Replace localFile URL</code></p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Auto</span> <span class="string">deploy</span></span><br><span class="line"><span class="comment"># 当有改动推送到master分支时,启动Action</span></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line"> <span class="attr">workflow_dispatch:</span></span><br><span class="line"> <span class="attr">push:</span></span><br><span class="line"> <span class="attr">branches:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"> <span class="attr">deploy:</span></span><br><span class="line"> <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line"> <span class="attr">steps:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">检查分支</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/checkout@v2</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">ref:</span> <span class="string">main</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">uses:</span> <span class="string">szenius/set-timezone@v1.0</span> <span class="comment"># 设置执行环境的时区</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">timezoneLinux:</span> <span class="string">"Asia/Shanghai"</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">安装</span> <span class="string">Node</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/setup-node@v1</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">node-version:</span> <span class="string">"18.x"</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">安装</span> <span class="string">Hexo</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> export TZ='Asia/Shanghai'</span></span><br><span class="line"><span class="string"> npm install hexo-cli -g</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">缓存</span> <span class="string">Hexo</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/cache@v1</span></span><br><span class="line"> <span class="attr">id:</span> <span class="string">cache</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">node_modules</span></span><br><span class="line"> <span class="attr">key:</span> <span class="string">${{runner.OS}}-${{hashFiles('**/package-lock.json')}}</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">安装依赖</span></span><br><span class="line"> <span class="attr">if:</span> <span class="string">steps.cache.outputs.cache-hit</span> <span class="type">!=</span> <span class="string">'true'</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> npm install gulp-cli -g #全局安装gulp</span></span><br><span class="line"><span class="string"> npm install --save</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Generate</span> <span class="string">static</span> <span class="string">file</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> hexo clean ; hexo generate ; gulp</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Set</span> <span class="string">up</span> <span class="string">Python</span> <span class="number">3.10</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/setup-python@v3</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">python-version:</span> <span class="string">"3.10"</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Install</span> <span class="string">dependencies</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> python -m pip install --upgrade pip</span></span><br><span class="line"><span class="string"> pip install requests</span></span><br><span class="line"><span class="string"></span> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Replace</span> <span class="string">imageBed</span> <span class="string">URL</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> python .github/replace-imgbed-url-v2.py</span></span><br><span class="line"><span class="string"></span> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Replace</span> <span class="string">localFile</span> <span class="string">URL</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> python .github/replace-localfile-url.py</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Delete</span> <span class="string">static</span> <span class="string">file</span> <span class="string">repository</span> <span class="string">tags</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> mkdir tmp_mycpen</span></span><br><span class="line"><span class="string"> cd tmp_mycpen</span></span><br><span class="line"><span class="string"> git clone https://github.com/mycpen/blog.git</span></span><br><span class="line"><span class="string"> cd blog</span></span><br><span class="line"><span class="string"> git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" --delete $(git tag -l)</span></span><br><span class="line"><span class="string"> cd ../..</span></span><br><span class="line"><span class="string"> rm -rf tmp_mycpen</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Deploy</span> <span class="string">static</span> <span class="string">file</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> cd ./public</span></span><br><span class="line"><span class="string"> git init</span></span><br><span class="line"><span class="string"> git config --global user.email 'github-actions[bot]@users.noreply.github.com'</span></span><br><span class="line"><span class="string"> git config --global user.name 'github-actions[bot]'</span></span><br><span class="line"><span class="string"> git add .</span></span><br><span class="line"><span class="string"> git commit -m "$(date +'%Y/%m/%d')"</span></span><br><span class="line"><span class="string"> tag_name=$(date +'%y.%m.%d')</span></span><br><span class="line"><span class="string"> git tag $tag_name</span></span><br><span class="line"><span class="string"> git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" $tag_name</span></span><br><span class="line"><span class="string"> git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" master:main</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Purge</span> <span class="string">JSD</span> <span class="string">cache</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> jsd_purge_urls=("https://purge.jsdelivr.net/gh/mycpen/blog/" "https://purge.jsdelivr.net/gh/mycpen/blog@latest/" "https://purge.jsdelivr.net/gh/mycpen/blog@main/")</span></span><br><span class="line"><span class="string"> for url in "${jsd_purge_urls[@]}"; do curl -s $url; done</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">推送百度</span> <span class="string">url</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> hexo deploy</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Delete</span> <span class="string">workflow</span> <span class="string">runs</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">Mattraks/delete-workflow-runs@v2</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">token:</span> <span class="string">${{</span> <span class="string">secrets.GH_TOKEN</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">repository:</span> <span class="string">${{</span> <span class="string">github.repository</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">retain_days:</span> <span class="number">30</span></span><br><span class="line"> <span class="attr">keep_minimum_runs:</span> <span class="number">6</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="参考">参考<a class="header-anchor" href="#参考"></a></h2><ol><li class="lvl-3"><p><a href="https://akilar.top/posts/e82444a6/">akilar | github-action推送博客部署仓库至NPM</a></p></li><li class="lvl-3"><p><a href="https://akilar.top/posts/3e956346/">akilar | npm图床</a></p></li><li class="lvl-3"><p><a href="https://blog.anheyu.com/posts/b228.html">安知鱼 | hexo博客工作流CI</a></p></li><li class="lvl-3"><p><a href="https://blog.anheyu.com/posts/72ea.html">安知鱼 | npm图床</a></p></li><li class="lvl-3"><p><a href="https://www.cnblogs.com/index-html/p/npm-upload.html#%E6%97%A0%E7%8A%B6%E6%80%81">EtherDream | 文件一键上传到 NPM</a></p></li><li class="lvl-3"><p><a href="https://npmmirror.com/">npmmirror | 同步模块 cnpm sync cnpmcore</a></p></li><li class="lvl-3"><p><a href="https://github.com/ChenYFan/CyanBlog/blob/main/prescripts/pkgpublish.js">github | CyanBlog/pkgpublish.js</a></p></li></ol>]]></content>
|
12
12
|
|
13
13
|
|
14
14
|
<categories>
|
@@ -269,7 +269,7 @@
|
|
269
269
|
<link href="/posts/fe8dbc73.html"/>
|
270
270
|
<url>/posts/fe8dbc73.html</url>
|
271
271
|
|
272
|
-
<content type="html"><![CDATA[<h2 id="前言">前言<a class="header-anchor" href="#前言"></a></h2><p>记录一些遇到的问题</p><h2 id="01-Python-中文乱码-Git-Bash">01. Python 中文乱码 (Git Bash)<a class="header-anchor" href="#01-Python-中文乱码-Git-Bash"></a></h2><p>win终端正常运行但是在git bash 终端运行py文件中文乱码<br>在python命令前加 <code>winpty</code> 之后则可以正常显示中文</p><blockquote><p>winpty:一个 Windows 软件包,提供类似于 Unix pty-master 的接口,用于与 Windows 控制台程序通信。</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202303310016695.png" alt="image-20230331001601640" style="zoom: 25%;" /></blockquote><p>参考文章:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/sinat_42414027/article/details/127787059">【python中文乱码】git bash终端运行python文件中文乱码的问题</a></p></li><li class="lvl-3"><p><a href="https://github.com/rprichard/winpty">https://github.com/rprichard/winpty</a></p></li></ol><h2 id="02-gitignore-测试规则">02. .gitignore 测试规则<a class="header-anchor" href="#02-gitignore-测试规则"></a></h2><p>.gitignore 配置</p><blockquote><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">*.a 表示忽略所有 .a 结尾的文件</span><br><span class="line">!lib.a 表示但lib.a除外</span><br><span class="line">doc/*.txt 表示会忽略doc/notes.txt但不包括 doc/server/arch.txt</span><br><span class="line">/TODO 表示仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO</span><br><span class="line">bin/ 表示忽略当前路径下的bin文件夹,该文件夹下的所有内容都会被忽略,不忽略 bin 文件</span><br><span class="line">**/foo: 表示忽略/foo,a/foo,a/b/foo等</span><br><span class="line">a/**/b: 表示忽略a/b, a/x/b,a/x/y/b等</span><br><span class="line">*.log: 表示忽略所有 .log 文件</span><br><span class="line">/mtk/ 表示过滤整个文件夹</span><br><span class="line">*.zip 表示过滤所有.zip文件</span><br><span class="line">--- 需要注意的是,gitignore还可以指定要将哪些文件添加到版本管理中,如下: ---</span><br><span class="line">!*.zip</span><br><span class="line">!/mtk/one.txt</span><br><span class="line">唯一的区别就是规则开头多了一个感叹号,Git会将满足这类规则的文件添加到版本管理中。为什么要有两种规则呢?</span><br><span class="line">想象一个场景:假如我们只需要管理/mtk/目录中的one.txt文件,</span><br><span class="line">这个目录中的其他文件都不需要管理,那么.gitignore规则应写为:</span><br><span class="line">/mtk/*</span><br><span class="line">!/mtk/one.txt</span><br><span class="line">假设我们只有过滤规则,而没有添加规则,</span><br><span class="line">那么我们就需要把/mtk/目录下除了one.txt以外的所有文件都写出来!</span><br><span class="line">注意上面的/mtk/*不能写为/mtk/,否则父目录被前面的规则排除掉了,</span><br><span class="line">one.txt文件虽然加了!过滤规则,也不会生效!</span><br><span class="line">--- 还有一些规则如下: ---</span><br><span class="line">fd1/*</span><br><span class="line">说明:忽略目录 fd1 下的全部内容;</span><br><span class="line">注意,不管是根目录下的 /fd1/ 目录,还是某个子目录 /child/fd1/ 目录,都会被忽略;</span><br><span class="line">/fd1/*</span><br><span class="line">说明:忽略根目录下的 /fd1/ 目录的全部内容;</span><br><span class="line">------</span><br><span class="line">/*</span><br><span class="line">!.gitignore</span><br><span class="line">!/fw/ </span><br><span class="line">/fw/*</span><br><span class="line">!/fw/bin/</span><br><span class="line">!/fw/sf/</span><br><span class="line">说明:忽略全部内容,但是不忽略 .gitignore 文件、根目录下的 /fw/bin/ 和 /fw/sf/ 目录;</span><br><span class="line">注意要先对bin/的父目录使用!规则,使其不被排除。</span><br><span class="line"></span><br></pre></td></tr></table></figure></blockquote><p><mark>*</mark> .gitignor 忽略规则查看</p><blockquote><p>有时候,确定为什么要忽略特定文件可能会很困难,尤其是当你使用多个.gitignore文件或复杂格式时。这是git check-ignore命令的用处,告诉git显示匹配模式的详细信息。</p><p>例如,要检查为什么忽略www/yarn.lock文件,可以运行:</p><p><code>git check-ignore -v www/yarn.lock</code></p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202304041447156.png" alt="image-20230404144757129" style="zoom: 67%;" /></blockquote><p>显示所有被忽略的文件</p><blockquote><p>带有–ignored选项的git status命令显示所有被忽略文件的列表:</p><p><code>git status --ignored</code></p></blockquote><p>参考文章:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/stephenbruce/article/details/127355631">Git忽略提交规则 - .gitignore配置【学习】</a></p></li><li class="lvl-3"><p><a href="https://blog.csdn.net/m0_49448331/article/details/128655710">如何使用.gitignore忽略Git中的文件和目录</a></p></li></ol><h2 id="03-Windows-显示-无Internet">03. Windows 显示"无Internet"<a class="header-anchor" href="#03-Windows-显示-无Internet"></a></h2><p>情况:网络显示 “无Internet”,但是可以上网。以下措施没根本解决,最终用微软诊断工具,重置了 <code>以太网</code> 网络(万能的重装大法)…</p><blockquote><ol><li class="lvl-3"><p>向 <a href="http://dns.msftncsi.com">dns.msftncsi.com</a> 发送 DNS 查找请求,DNS 解析为 131.107.255.255</p></li><li class="lvl-3"><p>请求 <a href="http://www.msftconnecttest.com/connecttest.txt%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%BD%91%E7%BB%9C%E6%AD%A3%E5%B8%B8%EF%BC%8C%E5%88%99%E6%AD%A4%E6%96%87%E4%BB%B6%E6%98%AF%E7%BA%AF%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6%EF%BC%8C%E4%BB%85%E5%8C%85%E5%90%AB%E6%96%87%E6%9C%AC">http://www.msftconnecttest.com/connecttest.txt,如果网络正常,则此文件是纯文本文件,仅包含文本</a> Microsoft Connect Test</p></li></ol><p>如果过程1不正常,则提示“无法访问Internet”,如果1正常2不正常,则提示需要进行身份验证</p></blockquote><p><mark>以下措施没解决问题</mark></p><p>估计 DHCP 分配的 DNS 服务器(指向网关)有问题,<a href="https://github.com/oldj/SwitchHosts">SwitchHosts</a> 追加本地记录</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Microsoft</span></span><br><span class="line">dns.msftncsi.com 131.107.255.255</span><br></pre></td></tr></table></figure><p>开机自启 SwitchHosts(Win):</p><ul class="lvl-0"><li class="lvl-2"><p>快捷方式 复制到 => C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\</p></li><li class="lvl-2"><p>设置 => 选项 => 启动时隐藏 √</p></li></ul><p>参考文章:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/wangpeng246300/article/details/120230220">解决Windows有网络连接但是显示“无Internet”的问题</a></p></li><li class="lvl-3"><p><a href="https://github.com/oldj/SwitchHosts/issues/646#issuecomment-945391940">SwitchHosts/issues/646</a></p></li></ol><h2 id="04-Replit-Repl-ERR-SSL-PROTOCOL-ERROR">04. Replit Repl ERR_SSL_PROTOCOL_ERROR<a class="header-anchor" href="#04-Replit-Repl-ERR-SSL-PROTOCOL-ERROR"></a></h2><p>未解决,绑自定义域名后,未分配 SSL 证书</p><p>Replit 官方论坛:</p><ol><li class="lvl-3"><p><a href="https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775">https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775</a></p></li><li class="lvl-3"><p>问题搜索:<a href="https://ask.replit.com/search?q=ERR_SSL_PROTOCOL_ERROR">https://ask.replit.com/search?q=ERR_SSL_PROTOCOL_ERROR</a></p></li></ol><p>Replit 官方服务状态:</p><ol><li class="lvl-3"><p><a href="https://status.replit.com/notices/ggj8gbnshk50a6yz-ssl-certificates-issues">SSL 证书问题</a></p></li><li class="lvl-3"><p><a href="https://status.replit.com/notices/5pcyvknbltq1mrmg-new-custom-domains-with-deployments-are-experiencing-ssl-errors">部署的新自定义域遇到 SSL 错误</a></p></li></ol><p>临时方案:</p><ol><li class="lvl-3"><p><a href="https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775/4">https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775/4</a></p><blockquote><p>现在,更改“。” 在 url 中的 repl 名称和用户名之间添加到“–”就可以了。</p><p>例如,<a href="https://score-analyzer--enderparakeet.repl.co/">https://score-analyzer–enderparakeet.repl.co/ 3个</a>作品。</p></blockquote></li></ol><p>教程:</p><ol><li class="lvl-3"><p><a href="https://docs.replit.com/tutorials/html-css-js/building-a-nineties-inspired-website#custom-domain">Replit 绑自定义域名(官方)</a></p></li></ol><h2 id="05-Terminal-报错-4294967295">05. Terminal 报错: 4294967295<a class="header-anchor" href="#05-Terminal-报错-4294967295"></a></h2><p>wsl2 报错: <code>[已退出进程,代码为 4294967295 (0xffffffff)]</code>,终端无法打开</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 管理员身份 PowerShell</span></span><br><span class="line">netsh winsock reset</span><br><span class="line"></span><br><span class="line"><span class="comment"># 重新打开 terminal,无效则尝试重启后再打开</span></span><br></pre></td></tr></table></figure><p>参考:<a href="https://blog.csdn.net/weixin_53347816/article/details/123637289">打开wsl,显示 [已退出进程,代码为 4294967295] 的解决方案</a></p><p>后记:未根本解决,根本错误 wsl <code>Error: 0x80040326</code>,如下</p><h2 id="06-wsl2-Error-0x80040326">06. wsl2 Error: 0x80040326<a class="header-anchor" href="#06-wsl2-Error-0x80040326"></a></h2><p>无法打开终端,报错:</p><p><code>Error: 0x80040326 Error code: Wsl/Service/0x80040326</code></p><p>解决方法:powershell 管理员模式:<code>wsl --update</code></p><p>参考:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/minibirder/article/details/129863725">https://blog.csdn.net/minibirder/article/details/129863725</a></p></li><li class="lvl-3"><p><a href="https://blog.csdn.net/qq_37932051/article/details/129873314">https://blog.csdn.net/qq_37932051/article/details/129873314</a></p></li></ol><h2 id="07-crond-致-sendmail-大量进程">07. crond 致 sendmail 大量进程<a class="header-anchor" href="#07-crond-致-sendmail-大量进程"></a></h2><p>阿里云服务器监控显示 CPU 长期高负载,原因:<code>定时任务 crond 引发大量 sendmail 进程</code></p><p>参考:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/LQzhang_11/article/details/114323700">https://blog.csdn.net/LQzhang_11/article/details/114323700</a></p></li><li class="lvl-3"><p><a href="https://blog.51cto.com/ning235/2661806">https://blog.51cto.com/ning235/2661806</a></p></li></ol><p>处理方法:</p><ol><li class="lvl-3"><p>cron 后面添加 <code>&> /dev/null</code> 或 <code>> /dev/null 2>&1</code></p></li><li class="lvl-3"><p>禁止 cron 发用户邮件(未操作)</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202309051546612.png" alt=""></p></li></ol><h2 id="08-Netlify-自动转换小写-URI">08. Netlify 自动转换小写 URI<a class="header-anchor" href="#08-Netlify-自动转换小写-URI"></a></h2><p>现象:原 URI <code>/tags/Error/</code> 转为 <code>/tags/error/</code></p><p>解决:配置中取消 <code>Pretty URLs</code> 美化 URL 的功能</p><ul class="lvl-0"><li class="lvl-2"><p><code>Site configuration</code> → <code>Post processing</code> → <code>Pretty URLs</code> → □ <code>Enable Pretty URLs</code></p></li></ul><p>示例:<a href="https://app.netlify.com/sites/mycpen-blog/configuration/deploys#pretty-urls">https://app.netlify.com/sites/mycpen-blog/configuration/deploys#pretty-urls</a></p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202310042038361.png" alt="image-20231004203836279" style="zoom:25%;" /><h2 id="09-pip-command-not-found">09. pip: command not found<a class="header-anchor" href="#09-pip-command-not-found"></a></h2><p>前言:电脑上已装 Python,且在 PATH 内,无法找到 pip 命令</p><p>报错:<code>pip: command not found</code> 或 <code>No module named pip</code></p><p>升级 pip:<code>python -m pip install --upgrade pip</code></p><p>办法:执行 <code>python -m ensurepip</code></p><blockquote><p><strong>来自 chatgpt</strong></p><p>在 Windows 系统上,如果您在运行 <code>python.exe</code> 时遇到 <code>No module named pip</code> 错误,这通常表示在您的 Python 安装中缺少了 <code>pip</code> 模块。<code>pip</code> 是 Python 的包管理工具,通常会随 Python 一起安装。</p><p>您可以按照以下步骤来解决这个问题:</p><ol><li class="lvl-3"><p>检查 Python 安装:</p></li></ol><p>首先,请确保您已经正确安装 Python。您可以在命令提示符下运行以下命令来检查 Python 的版本:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python --version</span><br></pre></td></tr></table></figure><ol start="2"><li class="lvl-3"><p>检查 <code>pip</code> 是否安装:</p></li></ol><p>在较新版本的 Python 中,<code>pip</code> 已经随 Python 一起安装。您可以尝试运行以下命令来安装 Python 包:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python -m ensurepip</span><br></pre></td></tr></table></figure><p>这将安装 <code>pip</code> 模块。如果 <code>pip</code> 已经安装,您可能会看到一条消息指示 <code>Requirement already satisfied</code>.</p><ol start="3"><li class="lvl-3"><p>添加 <code>pip</code> 到系统环境变量:</p></li></ol><p>如果 <code>pip</code> 已正确安装,但仍然无法正常使用,可能是因为 <code>pip</code> 不在系统的环境变量中。您可以手动将 <code>pip</code> 所在的路径添加到系统的 PATH 环境变量中。</p><p>默认情况下,在 Windows 系统上,<code>pip</code> 通常安装在 <code>Scripts</code> 文件夹中。您可以找到该文件夹的路径,然后将其添加到系统的 PATH 环境变量中。</p><ol start="4"><li class="lvl-3"><p>验证 <code>pip</code> 安装:</p></li></ol><p>最后,您可以在命令提示符下运行以下命令来验证 <code>pip</code> 是否安装成功:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip --version</span><br></pre></td></tr></table></figure><p>如果 <code>pip</code> 安装成功,您应该看到 <code>pip</code> 的版本信息,而不再出现 <code>No module named pip</code> 错误。</p><p>通过按照上述步骤操作,您应该能够解决 <code>No module named pip</code> 错误,并成功使用 <code>pip</code> 来管理 Python 包。</p></blockquote><h2 id="10-git-fetch-unshallow">10. git fetch --unshallow<a class="header-anchor" href="#10-git-fetch-unshallow"></a></h2><p>github action 报错 <code>! [remote rejected] main -> main (shallow update not allowed)</code></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">remote: Powered by GITEE.COM [GNK-6.4] </span><br><span class="line">To https://gitee.com/mycpen/image_bed.git</span><br><span class="line"> ! [remote rejected] main -> main (shallow update not allowed)</span><br><span class="line">error: failed to push some refs to <span class="string">'https://gitee.com/mycpen/image_bed.git'</span></span><br><span class="line">Error: Process completed with <span class="built_in">exit</span> code 1.</span><br></pre></td></tr></table></figure><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fyunetadxq/image/202405102346367.jpg" alt="image-20240510234628717" style="zoom: 50%;" /><p>解决:<code>git fetch --unshallow</code>,详见 <a href="https://github.com/mycpen/image_bed/blob/main/.github/workflows/sync-gitee.yml">link</a></p><blockquote><p>来自 chatgpt</p><p>这个错误是因为在尝试将代码推送到 Gitee 仓库时,Gitee 不允许进行浅层更新(shallow update)。浅层更新是指仓库中只包含部分历史记录,而不是完整的历史记录。为了解决这个问题,你可以尝试以下方法:</p><ol><li class="lvl-3"><p><strong>完整克隆</strong>:首先,你可以通过完整克隆仓库的方式来获取完整的历史记录,然后再进行推送。在克隆仓库时,不要使用 <code>--depth</code> 参数,这样可以确保克隆完整的历史记录。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://gitee.com/mycpen/CDN.git</span><br></pre></td></tr></table></figure></li><li class="lvl-3"><p><strong>移除浅层设置后重新克隆</strong>:如果你之前使用了浅层克隆,可以尝试移除浅层设置,然后重新克隆仓库。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git fetch --unshallow</span><br><span class="line">git <span class="built_in">clone</span> https://gitee.com/mycpen/CDN.git</span><br></pre></td></tr></table></figure></li><li class="lvl-3"><p><strong>强制推送</strong>:如果你已经有本地完整的历史记录,可以尝试使用强制推送来覆盖远程仓库的内容。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push -f origin main</span><br></pre></td></tr></table></figure></li></ol><p>通过以上方法,你应该能够解决 Gitee 仓库不允许浅层更新的问题,并成功将代码推送到 Gitee 仓库中。如果你有任何其他问题或需要进一步帮助,请随时告诉我。</p></blockquote>]]></content>
|
272
|
+
<content type="html"><![CDATA[<h2 id="前言">前言<a class="header-anchor" href="#前言"></a></h2><p>记录一些遇到的问题</p><h2 id="01-Python-中文乱码-Git-Bash">01. Python 中文乱码 (Git Bash)<a class="header-anchor" href="#01-Python-中文乱码-Git-Bash"></a></h2><p>win终端正常运行但是在git bash 终端运行py文件中文乱码<br>在python命令前加 <code>winpty</code> 之后则可以正常显示中文</p><blockquote><p>winpty:一个 Windows 软件包,提供类似于 Unix pty-master 的接口,用于与 Windows 控制台程序通信。</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202303310016695.png" alt="image-20230331001601640" style="zoom: 25%;" /></blockquote><p>参考文章:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/sinat_42414027/article/details/127787059">【python中文乱码】git bash终端运行python文件中文乱码的问题</a></p></li><li class="lvl-3"><p><a href="https://github.com/rprichard/winpty">https://github.com/rprichard/winpty</a></p></li></ol><h2 id="02-gitignore-测试规则">02. .gitignore 测试规则<a class="header-anchor" href="#02-gitignore-测试规则"></a></h2><p>.gitignore 配置</p><blockquote><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">*.a 表示忽略所有 .a 结尾的文件</span><br><span class="line">!lib.a 表示但lib.a除外</span><br><span class="line">doc/*.txt 表示会忽略doc/notes.txt但不包括 doc/server/arch.txt</span><br><span class="line">/TODO 表示仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO</span><br><span class="line">bin/ 表示忽略当前路径下的bin文件夹,该文件夹下的所有内容都会被忽略,不忽略 bin 文件</span><br><span class="line">**/foo: 表示忽略/foo,a/foo,a/b/foo等</span><br><span class="line">a/**/b: 表示忽略a/b, a/x/b,a/x/y/b等</span><br><span class="line">*.log: 表示忽略所有 .log 文件</span><br><span class="line">/mtk/ 表示过滤整个文件夹</span><br><span class="line">*.zip 表示过滤所有.zip文件</span><br><span class="line">--- 需要注意的是,gitignore还可以指定要将哪些文件添加到版本管理中,如下: ---</span><br><span class="line">!*.zip</span><br><span class="line">!/mtk/one.txt</span><br><span class="line">唯一的区别就是规则开头多了一个感叹号,Git会将满足这类规则的文件添加到版本管理中。为什么要有两种规则呢?</span><br><span class="line">想象一个场景:假如我们只需要管理/mtk/目录中的one.txt文件,</span><br><span class="line">这个目录中的其他文件都不需要管理,那么.gitignore规则应写为:</span><br><span class="line">/mtk/*</span><br><span class="line">!/mtk/one.txt</span><br><span class="line">假设我们只有过滤规则,而没有添加规则,</span><br><span class="line">那么我们就需要把/mtk/目录下除了one.txt以外的所有文件都写出来!</span><br><span class="line">注意上面的/mtk/*不能写为/mtk/,否则父目录被前面的规则排除掉了,</span><br><span class="line">one.txt文件虽然加了!过滤规则,也不会生效!</span><br><span class="line">--- 还有一些规则如下: ---</span><br><span class="line">fd1/*</span><br><span class="line">说明:忽略目录 fd1 下的全部内容;</span><br><span class="line">注意,不管是根目录下的 /fd1/ 目录,还是某个子目录 /child/fd1/ 目录,都会被忽略;</span><br><span class="line">/fd1/*</span><br><span class="line">说明:忽略根目录下的 /fd1/ 目录的全部内容;</span><br><span class="line">------</span><br><span class="line">/*</span><br><span class="line">!.gitignore</span><br><span class="line">!/fw/ </span><br><span class="line">/fw/*</span><br><span class="line">!/fw/bin/</span><br><span class="line">!/fw/sf/</span><br><span class="line">说明:忽略全部内容,但是不忽略 .gitignore 文件、根目录下的 /fw/bin/ 和 /fw/sf/ 目录;</span><br><span class="line">注意要先对bin/的父目录使用!规则,使其不被排除。</span><br><span class="line"></span><br></pre></td></tr></table></figure></blockquote><p><mark>*</mark> .gitignor 忽略规则查看</p><blockquote><p>有时候,确定为什么要忽略特定文件可能会很困难,尤其是当你使用多个.gitignore文件或复杂格式时。这是git check-ignore命令的用处,告诉git显示匹配模式的详细信息。</p><p>例如,要检查为什么忽略www/yarn.lock文件,可以运行:</p><p><code>git check-ignore -v www/yarn.lock</code></p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202304041447156.png" alt="image-20230404144757129" style="zoom: 67%;" /></blockquote><p>显示所有被忽略的文件</p><blockquote><p>带有–ignored选项的git status命令显示所有被忽略文件的列表:</p><p><code>git status --ignored</code></p></blockquote><p>参考文章:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/stephenbruce/article/details/127355631">Git忽略提交规则 - .gitignore配置【学习】</a></p></li><li class="lvl-3"><p><a href="https://blog.csdn.net/m0_49448331/article/details/128655710">如何使用.gitignore忽略Git中的文件和目录</a></p></li></ol><h2 id="03-Windows-显示-无Internet">03. Windows 显示"无Internet"<a class="header-anchor" href="#03-Windows-显示-无Internet"></a></h2><p>情况:网络显示 “无Internet”,但是可以上网。以下措施没根本解决,最终用微软诊断工具,重置了 <code>以太网</code> 网络(万能的重装大法)…</p><blockquote><ol><li class="lvl-3"><p>向 <a href="http://dns.msftncsi.com">dns.msftncsi.com</a> 发送 DNS 查找请求,DNS 解析为 131.107.255.255</p></li><li class="lvl-3"><p>请求 <a href="http://www.msftconnecttest.com/connecttest.txt%EF%BC%8C%E5%A6%82%E6%9E%9C%E7%BD%91%E7%BB%9C%E6%AD%A3%E5%B8%B8%EF%BC%8C%E5%88%99%E6%AD%A4%E6%96%87%E4%BB%B6%E6%98%AF%E7%BA%AF%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6%EF%BC%8C%E4%BB%85%E5%8C%85%E5%90%AB%E6%96%87%E6%9C%AC">http://www.msftconnecttest.com/connecttest.txt,如果网络正常,则此文件是纯文本文件,仅包含文本</a> Microsoft Connect Test</p></li></ol><p>如果过程1不正常,则提示“无法访问Internet”,如果1正常2不正常,则提示需要进行身份验证</p></blockquote><p><mark>以下措施没解决问题</mark></p><p>估计 DHCP 分配的 DNS 服务器(指向网关)有问题,<a href="https://github.com/oldj/SwitchHosts">SwitchHosts</a> 追加本地记录</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Microsoft</span></span><br><span class="line">dns.msftncsi.com 131.107.255.255</span><br></pre></td></tr></table></figure><p>开机自启 SwitchHosts(Win):</p><ul class="lvl-0"><li class="lvl-2"><p>快捷方式 复制到 => C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\</p></li><li class="lvl-2"><p>设置 => 选项 => 启动时隐藏 √</p></li></ul><p>参考文章:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/wangpeng246300/article/details/120230220">解决Windows有网络连接但是显示“无Internet”的问题</a></p></li><li class="lvl-3"><p><a href="https://github.com/oldj/SwitchHosts/issues/646#issuecomment-945391940">SwitchHosts/issues/646</a></p></li></ol><h2 id="04-Replit-Repl-ERR-SSL-PROTOCOL-ERROR">04. Replit Repl ERR_SSL_PROTOCOL_ERROR<a class="header-anchor" href="#04-Replit-Repl-ERR-SSL-PROTOCOL-ERROR"></a></h2><p>未解决,绑自定义域名后,未分配 SSL 证书</p><p>Replit 官方论坛:</p><ol><li class="lvl-3"><p><a href="https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775">https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775</a></p></li><li class="lvl-3"><p>问题搜索:<a href="https://ask.replit.com/search?q=ERR_SSL_PROTOCOL_ERROR">https://ask.replit.com/search?q=ERR_SSL_PROTOCOL_ERROR</a></p></li></ol><p>Replit 官方服务状态:</p><ol><li class="lvl-3"><p><a href="https://status.replit.com/notices/ggj8gbnshk50a6yz-ssl-certificates-issues">SSL 证书问题</a></p></li><li class="lvl-3"><p><a href="https://status.replit.com/notices/5pcyvknbltq1mrmg-new-custom-domains-with-deployments-are-experiencing-ssl-errors">部署的新自定义域遇到 SSL 错误</a></p></li></ol><p>临时方案:</p><ol><li class="lvl-3"><p><a href="https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775/4">https://ask.replit.com/t/err-ssl-protocol-error-for-all-sites/27775/4</a></p><blockquote><p>现在,更改“。” 在 url 中的 repl 名称和用户名之间添加到“–”就可以了。</p><p>例如,<a href="https://score-analyzer--enderparakeet.repl.co/">https://score-analyzer–enderparakeet.repl.co/ 3个</a>作品。</p></blockquote></li></ol><p>教程:</p><ol><li class="lvl-3"><p><a href="https://docs.replit.com/tutorials/html-css-js/building-a-nineties-inspired-website#custom-domain">Replit 绑自定义域名(官方)</a></p></li></ol><h2 id="05-Terminal-报错-4294967295">05. Terminal 报错: 4294967295<a class="header-anchor" href="#05-Terminal-报错-4294967295"></a></h2><p>wsl2 报错: <code>[已退出进程,代码为 4294967295 (0xffffffff)]</code>,终端无法打开</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 管理员身份 PowerShell</span></span><br><span class="line">netsh winsock reset</span><br><span class="line"></span><br><span class="line"><span class="comment"># 重新打开 terminal,无效则尝试重启后再打开</span></span><br></pre></td></tr></table></figure><p>参考:<a href="https://blog.csdn.net/weixin_53347816/article/details/123637289">打开wsl,显示 [已退出进程,代码为 4294967295] 的解决方案</a></p><p>后记:未根本解决,根本错误 wsl <code>Error: 0x80040326</code>,如下</p><h2 id="06-wsl2-Error-0x80040326">06. wsl2 Error: 0x80040326<a class="header-anchor" href="#06-wsl2-Error-0x80040326"></a></h2><p>无法打开终端,报错:</p><p><code>Error: 0x80040326 Error code: Wsl/Service/0x80040326</code></p><p>解决方法:powershell 管理员模式:<code>wsl --update</code></p><p>参考:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/minibirder/article/details/129863725">https://blog.csdn.net/minibirder/article/details/129863725</a></p></li><li class="lvl-3"><p><a href="https://blog.csdn.net/qq_37932051/article/details/129873314">https://blog.csdn.net/qq_37932051/article/details/129873314</a></p></li></ol><h2 id="07-crond-致-sendmail-大量进程">07. crond 致 sendmail 大量进程<a class="header-anchor" href="#07-crond-致-sendmail-大量进程"></a></h2><p>阿里云服务器监控显示 CPU 长期高负载,原因:<code>定时任务 crond 引发大量 sendmail 进程</code></p><p>参考:</p><ol><li class="lvl-3"><p><a href="https://blog.csdn.net/LQzhang_11/article/details/114323700">https://blog.csdn.net/LQzhang_11/article/details/114323700</a></p></li><li class="lvl-3"><p><a href="https://blog.51cto.com/ning235/2661806">https://blog.51cto.com/ning235/2661806</a></p></li></ol><p>处理方法:</p><ol><li class="lvl-3"><p>cron 后面添加 <code>&> /dev/null</code> 或 <code>> /dev/null 2>&1</code></p></li><li class="lvl-3"><p>禁止 cron 发用户邮件(未操作)</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202309051546612.png" alt=""></p></li></ol><h2 id="08-Netlify-自动转换小写-URI">08. Netlify 自动转换小写 URI<a class="header-anchor" href="#08-Netlify-自动转换小写-URI"></a></h2><p>现象:原 URI <code>/tags/Error/</code> 转为 <code>/tags/error/</code></p><p>解决:配置中取消 <code>Pretty URLs</code> 美化 URL 的功能</p><ul class="lvl-0"><li class="lvl-2"><p><code>Site configuration</code> → <code>Post processing</code> → <code>Pretty URLs</code> → □ <code>Enable Pretty URLs</code></p></li></ul><p>示例:<a href="https://app.netlify.com/sites/mycpen-blog/configuration/deploys#pretty-urls">https://app.netlify.com/sites/mycpen-blog/configuration/deploys#pretty-urls</a></p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202310042038361.png" alt="image-20231004203836279" style="zoom:25%;" /><h2 id="09-pip-command-not-found">09. pip: command not found<a class="header-anchor" href="#09-pip-command-not-found"></a></h2><p>前言:电脑上已装 Python,且在 PATH 内,无法找到 pip 命令</p><p>报错:<code>pip: command not found</code> 或 <code>No module named pip</code></p><p>升级 pip:<code>python -m pip install --upgrade pip</code></p><p>办法:执行 <code>python -m ensurepip</code></p><blockquote><p><strong>来自 chatgpt</strong></p><p>在 Windows 系统上,如果您在运行 <code>python.exe</code> 时遇到 <code>No module named pip</code> 错误,这通常表示在您的 Python 安装中缺少了 <code>pip</code> 模块。<code>pip</code> 是 Python 的包管理工具,通常会随 Python 一起安装。</p><p>您可以按照以下步骤来解决这个问题:</p><ol><li class="lvl-3"><p>检查 Python 安装:</p></li></ol><p>首先,请确保您已经正确安装 Python。您可以在命令提示符下运行以下命令来检查 Python 的版本:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python --version</span><br></pre></td></tr></table></figure><ol start="2"><li class="lvl-3"><p>检查 <code>pip</code> 是否安装:</p></li></ol><p>在较新版本的 Python 中,<code>pip</code> 已经随 Python 一起安装。您可以尝试运行以下命令来安装 Python 包:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python -m ensurepip</span><br></pre></td></tr></table></figure><p>这将安装 <code>pip</code> 模块。如果 <code>pip</code> 已经安装,您可能会看到一条消息指示 <code>Requirement already satisfied</code>.</p><ol start="3"><li class="lvl-3"><p>添加 <code>pip</code> 到系统环境变量:</p></li></ol><p>如果 <code>pip</code> 已正确安装,但仍然无法正常使用,可能是因为 <code>pip</code> 不在系统的环境变量中。您可以手动将 <code>pip</code> 所在的路径添加到系统的 PATH 环境变量中。</p><p>默认情况下,在 Windows 系统上,<code>pip</code> 通常安装在 <code>Scripts</code> 文件夹中。您可以找到该文件夹的路径,然后将其添加到系统的 PATH 环境变量中。</p><ol start="4"><li class="lvl-3"><p>验证 <code>pip</code> 安装:</p></li></ol><p>最后,您可以在命令提示符下运行以下命令来验证 <code>pip</code> 是否安装成功:</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip --version</span><br></pre></td></tr></table></figure><p>如果 <code>pip</code> 安装成功,您应该看到 <code>pip</code> 的版本信息,而不再出现 <code>No module named pip</code> 错误。</p><p>通过按照上述步骤操作,您应该能够解决 <code>No module named pip</code> 错误,并成功使用 <code>pip</code> 来管理 Python 包。</p></blockquote><h2 id="10-git-fetch-unshallow">10. git fetch --unshallow<a class="header-anchor" href="#10-git-fetch-unshallow"></a></h2><p>github action 报错 <code>! [remote rejected] main -> main (shallow update not allowed)</code></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">remote: Powered by GITEE.COM [GNK-6.4] </span><br><span class="line">To https://gitee.com/mycpen/image_bed.git</span><br><span class="line"> ! [remote rejected] main -> main (shallow update not allowed)</span><br><span class="line">error: failed to push some refs to <span class="string">'https://gitee.com/mycpen/image_bed.git'</span></span><br><span class="line">Error: Process completed with <span class="built_in">exit</span> code 1.</span><br></pre></td></tr></table></figure><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/202405102346367.jpg" alt="image-20240510234628717" style="zoom: 50%;" /><p>解决:<code>git fetch --unshallow</code>,详见 <a href="https://github.com/mycpen/image_bed/blob/main/.github/workflows/sync-gitee.yml">link</a></p><blockquote><p>来自 chatgpt</p><p>这个错误是因为在尝试将代码推送到 Gitee 仓库时,Gitee 不允许进行浅层更新(shallow update)。浅层更新是指仓库中只包含部分历史记录,而不是完整的历史记录。为了解决这个问题,你可以尝试以下方法:</p><ol><li class="lvl-3"><p><strong>完整克隆</strong>:首先,你可以通过完整克隆仓库的方式来获取完整的历史记录,然后再进行推送。在克隆仓库时,不要使用 <code>--depth</code> 参数,这样可以确保克隆完整的历史记录。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://gitee.com/mycpen/CDN.git</span><br></pre></td></tr></table></figure></li><li class="lvl-3"><p><strong>移除浅层设置后重新克隆</strong>:如果你之前使用了浅层克隆,可以尝试移除浅层设置,然后重新克隆仓库。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git fetch --unshallow</span><br><span class="line">git <span class="built_in">clone</span> https://gitee.com/mycpen/CDN.git</span><br></pre></td></tr></table></figure></li><li class="lvl-3"><p><strong>强制推送</strong>:如果你已经有本地完整的历史记录,可以尝试使用强制推送来覆盖远程仓库的内容。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git push -f origin main</span><br></pre></td></tr></table></figure></li></ol><p>通过以上方法,你应该能够解决 Gitee 仓库不允许浅层更新的问题,并成功将代码推送到 Gitee 仓库中。如果你有任何其他问题或需要进一步帮助,请随时告诉我。</p></blockquote>]]></content>
|
273
273
|
|
274
274
|
|
275
275
|
<categories>
|
@@ -460,7 +460,7 @@
|
|
460
460
|
<link href="/posts/3ffec809.html"/>
|
461
461
|
<url>/posts/3ffec809.html</url>
|
462
462
|
|
463
|
-
<content type="html"><![CDATA[<h2 id="2023-02-06-更新">2023/02/06 更新<a class="header-anchor" href="#2023-02-06-更新"></a></h2><p>VSCode 集成了 <code>某路径下的文件批量替换指定内容</code> 的功能,更方便</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202302061839251.png" alt="image-20230206183933193" style="zoom:50%;" /><h2 id="1-前言">1. 前言<a class="header-anchor" href="#1-前言"></a></h2><p>在 <a href="https://www.jsdelivr.com/">jsd</a> 失效之后,博主使用了新的图床方案,需将文章的原 jsd 图片链接替换为新的图片地址</p><p>这类脚本在网上有很多,都很推荐,如</p><ul class="lvl-0"><li class="lvl-2"><p><a href="https://blog.csdn.net/qq_38150250/article/details/118026219">批量修改文件内容(Python版)</a></p></li><li class="lvl-2"><p><a href="https://blog.zhheo.com/p/369dbf41.html">张洪Heo:用 Python 批量替换 md 文件内容</a></p></li><li class="lvl-2"><p><a href="https://blog.justlovesmile.top/posts/7a5857a0.html">Justlovesmile:如何自动下载、压缩并批量替换文章中的外链图片</a></p></li></ul><h2 id="2-脚本内容">2. 脚本内容<a class="header-anchor" href="#2-脚本内容"></a></h2><p>源码来自:<a href="https://blog.csdn.net/qq_38150250/article/details/118026219">批量修改文件内容(Python版)</a></p><p>脚本采用递归的方式,遍历 43~46 行 目录下的所有文件,进行批量替换</p><p>说明:</p><ol><li class="lvl-3"><p>根据自身情况修改 43~46 行 需遍历的目录;修改 47、48 行 需要替换的内容</p></li><li class="lvl-3"><p>脚本第 24 行 限制了只筛选出 Markdown 类型的文本文件进行修改,如需修改其他类型的文本文件 需自行更改后缀进行匹配</p></li><li class="lvl-3"><p>执行前请先备份源文件,以防出错后无法还原</p></li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 源码参考 https://blog.csdn.net/qq_38150250/article/details/118026219</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"></span><br><span class="line"><span class="comment"># 文件查找 find . -name file_name -type f</span></span><br><span class="line"><span class="comment"># 查找函数:search_path 查找根路径 </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取文章路径</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">search</span>(<span class="params">search_path, search_result</span>):</span><br><span class="line"> <span class="comment"># 获取当前路径下地所有文件</span></span><br><span class="line"> all_file = os.listdir(search_path)</span><br><span class="line"> <span class="comment"># 对于每一个文件</span></span><br><span class="line"> <span class="keyword">for</span> each_file <span class="keyword">in</span> all_file:</span><br><span class="line"> <span class="comment"># 若文件为一个文件夹</span></span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(search_path + each_file):</span><br><span class="line"> <span class="comment"># 递归查找</span></span><br><span class="line"> search(search_path + each_file + <span class="string">'/'</span>, search_result)</span><br><span class="line"> <span class="comment"># 如果是需要被查找的文件</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">if</span> re.findall(<span class="string">'.*\.md$'</span>, each_file) == [each_file]:</span><br><span class="line"> <span class="comment"># 输出路径</span></span><br><span class="line"> search_result.append(search_path + each_file)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 sed -i 's/old_str/new_str/'</span></span><br><span class="line"><span class="comment"># 文本替换 replace_file_name 需要替换的文件路径,replace_old_str 要替换的字符,replace_new_str 替换的字符</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">replace</span>(<span class="params">replace_file_name, replace_old_str, replace_new_str</span>):</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"r"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f1: </span><br><span class="line"> content = f1.read()</span><br><span class="line"> f1.close()</span><br><span class="line"> t = content.replace(replace_old_str, replace_new_str)</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"w"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f2:</span><br><span class="line"> f2.write(t)</span><br><span class="line"> f2.close()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 需要改的地方</span></span><br><span class="line"><span class="comment">#path = 'E:/code_zone/.history/20220831_blog/source/_posts/'</span></span><br><span class="line">path_list = [</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source/source/_posts/'</span>,</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source-butterfly/source/_posts/'</span>,</span><br><span class="line">]</span><br><span class="line">old_str = <span class="string">'https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-
|
463
|
+
<content type="html"><![CDATA[<h2 id="2023-02-06-更新">2023/02/06 更新<a class="header-anchor" href="#2023-02-06-更新"></a></h2><p>VSCode 集成了 <code>某路径下的文件批量替换指定内容</code> 的功能,更方便</p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2023/image/202302061839251.png" alt="image-20230206183933193" style="zoom:50%;" /><h2 id="1-前言">1. 前言<a class="header-anchor" href="#1-前言"></a></h2><p>在 <a href="https://www.jsdelivr.com/">jsd</a> 失效之后,博主使用了新的图床方案,需将文章的原 jsd 图片链接替换为新的图片地址</p><p>这类脚本在网上有很多,都很推荐,如</p><ul class="lvl-0"><li class="lvl-2"><p><a href="https://blog.csdn.net/qq_38150250/article/details/118026219">批量修改文件内容(Python版)</a></p></li><li class="lvl-2"><p><a href="https://blog.zhheo.com/p/369dbf41.html">张洪Heo:用 Python 批量替换 md 文件内容</a></p></li><li class="lvl-2"><p><a href="https://blog.justlovesmile.top/posts/7a5857a0.html">Justlovesmile:如何自动下载、压缩并批量替换文章中的外链图片</a></p></li></ul><h2 id="2-脚本内容">2. 脚本内容<a class="header-anchor" href="#2-脚本内容"></a></h2><p>源码来自:<a href="https://blog.csdn.net/qq_38150250/article/details/118026219">批量修改文件内容(Python版)</a></p><p>脚本采用递归的方式,遍历 43~46 行 目录下的所有文件,进行批量替换</p><p>说明:</p><ol><li class="lvl-3"><p>根据自身情况修改 43~46 行 需遍历的目录;修改 47、48 行 需要替换的内容</p></li><li class="lvl-3"><p>脚本第 24 行 限制了只筛选出 Markdown 类型的文本文件进行修改,如需修改其他类型的文本文件 需自行更改后缀进行匹配</p></li><li class="lvl-3"><p>执行前请先备份源文件,以防出错后无法还原</p></li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 源码参考 https://blog.csdn.net/qq_38150250/article/details/118026219</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"></span><br><span class="line"><span class="comment"># 文件查找 find . -name file_name -type f</span></span><br><span class="line"><span class="comment"># 查找函数:search_path 查找根路径 </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取文章路径</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">search</span>(<span class="params">search_path, search_result</span>):</span><br><span class="line"> <span class="comment"># 获取当前路径下地所有文件</span></span><br><span class="line"> all_file = os.listdir(search_path)</span><br><span class="line"> <span class="comment"># 对于每一个文件</span></span><br><span class="line"> <span class="keyword">for</span> each_file <span class="keyword">in</span> all_file:</span><br><span class="line"> <span class="comment"># 若文件为一个文件夹</span></span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(search_path + each_file):</span><br><span class="line"> <span class="comment"># 递归查找</span></span><br><span class="line"> search(search_path + each_file + <span class="string">'/'</span>, search_result)</span><br><span class="line"> <span class="comment"># 如果是需要被查找的文件</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">if</span> re.findall(<span class="string">'.*\.md$'</span>, each_file) == [each_file]:</span><br><span class="line"> <span class="comment"># 输出路径</span></span><br><span class="line"> search_result.append(search_path + each_file)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 sed -i 's/old_str/new_str/'</span></span><br><span class="line"><span class="comment"># 文本替换 replace_file_name 需要替换的文件路径,replace_old_str 要替换的字符,replace_new_str 替换的字符</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">replace</span>(<span class="params">replace_file_name, replace_old_str, replace_new_str</span>):</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"r"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f1: </span><br><span class="line"> content = f1.read()</span><br><span class="line"> f1.close()</span><br><span class="line"> t = content.replace(replace_old_str, replace_new_str)</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"w"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f2:</span><br><span class="line"> f2.write(t)</span><br><span class="line"> f2.close()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 需要改的地方</span></span><br><span class="line"><span class="comment">#path = 'E:/code_zone/.history/20220831_blog/source/_posts/'</span></span><br><span class="line">path_list = [</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source/source/_posts/'</span>,</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source-butterfly/source/_posts/'</span>,</span><br><span class="line">]</span><br><span class="line">old_str = <span class="string">'https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/'</span></span><br><span class="line">new_str = <span class="string">'https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/'</span></span><br><span class="line"></span><br><span class="line">search_result = []</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> result = [] <span class="comment"># 存放文件路径</span></span><br><span class="line"> <span class="comment"># 默认当前目录</span></span><br><span class="line"> <span class="comment"># path = os.getcwd()</span></span><br><span class="line"> <span class="keyword">for</span> path <span class="keyword">in</span> path_list:</span><br><span class="line"> search(path, result) <span class="comment"># 获取文章路径</span></span><br><span class="line"> count = <span class="number">0</span></span><br><span class="line"> <span class="keyword">for</span> file_name <span class="keyword">in</span> result:</span><br><span class="line"> replace(file_name, old_str, new_str)</span><br><span class="line"> count += <span class="number">1</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"{} done {}"</span>.<span class="built_in">format</span>(file_name, count))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 命令</span></span><br><span class="line"><span class="comment"># python E:/code_zone/tools/python-replace/replace.py</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="3-参考文章">3. 参考文章<a class="header-anchor" href="#3-参考文章"></a></h2><p>源码来自:<a href="https://blog.csdn.net/qq_38150250/article/details/118026219">批量修改文件内容(Python版)</a></p>]]></content>
|
464
464
|
|
465
465
|
|
466
466
|
<categories>
|
@@ -1016,7 +1016,7 @@
|
|
1016
1016
|
<link href="/posts/63259.html"/>
|
1017
1017
|
<url>/posts/63259.html</url>
|
1018
1018
|
|
1019
|
-
<content type="html"><![CDATA[<h2 id="一-前言">一. 前言<a class="header-anchor" href="#一-前言"></a></h2><p>因 <a href="https://www.jsdelivr.com/">https://www.jsdelivr.com/</a> 失效,博主打算将 GitHub 托管的图床备份到其他平台。</p><p>网上看到 <a href="https://github.com/lsky-org/lsky-pro">兰空图床</a> 萌生了自建图床的念头,搭建环境要求 PHP >= 8.0.2,于是打算编译安装 PHP。</p><p>最终因服务器配置太低(1核2G)编译失败而放弃。转而投身之前已经搭建好环境的又拍云平台。</p><p>博文内容:<code>PHP-CentOS8.2 编译安装 PHP8.1.10</code> + <code>编写GitHub图床迁移至又拍云的脚本(ftp)</code> + <code>编写批量修改文章内容的脚本</code></p><h2 id="二-正文">二. 正文<a class="header-anchor" href="#二-正文"></a></h2><h3 id="2-1❤-CentOS8-2-编译安装-PHP8-1-10">2.1❤ CentOS8.2 编译安装 PHP8.1.10<a class="header-anchor" href="#2-1❤-CentOS8-2-编译安装-PHP8-1-10"></a></h3><p><strong>2.1.1</strong> PHP8 和 oniguruma 源码下载并上传至服务器 /mnt 目录</p><p><a href="https://www.php.net/distributions/php-8.1.10.tar.gz">https://www.php.net/distributions/php-8.1.10.tar.gz</a></p><p><a href="https://codeload.github.com/kkos/oniguruma/tar.gz/refs/tags/v6.9.4">https://codeload.github.com/kkos/oniguruma/tar.gz/refs/tags/v6.9.4</a></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 解压</span></span><br><span class="line">tar xzf oniguruma-6.9.4.tar.gz</span><br><span class="line">tar xzf php-8.1.10.tar.gz</span><br></pre></td></tr></table></figure><p><strong>2.1.2</strong> 安装 PHP8 依赖包</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 2 安装 PHP8 依赖包</span></span><br><span class="line">yum -y install autoconf freetype gd libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-clients freetype-devel gmp-devel libzip libzip-devel sqlite-devel automake libtool</span><br></pre></td></tr></table></figure><p><strong>2.1.3</strong> 编译 PHP8 依赖包 oniguruma</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 3.1 生成 configure</span></span><br><span class="line"><span class="built_in">cd</span> /mnt/oniguruma-6.9.4</span><br><span class="line">./autogen.sh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.2 生成编译配置文件</span></span><br><span class="line">./configure --prefix=/usr</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.3 编译并安装</span></span><br><span class="line">make && make install</span><br></pre></td></tr></table></figure><p><strong>2.1.4</strong> 编译 PHP8 主包</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 4.1 生成编译配置文件</span></span><br><span class="line"><span class="built_in">cd</span> /mnt/php-8.1.10</span><br><span class="line">./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-mysqlnd --with-mysqli --with-pdo-mysql --enable-opcache --with-pcre-jit --enable-gd --with-jpeg --with-freetype --with-gettext --with-curl --with-openssl --enable-sockets --enable-mbstring --enable-xml --with-zip --with-zlib --with-snmp --with-mhash --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-pcntl --with-gmp</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.2 编译并安装</span></span><br><span class="line">make && make install</span><br></pre></td></tr></table></figure><p>因为配置过低,编译失败。</p><p><strong>2.1.5</strong> 编译安装后目录</p><p>/usr/local/php</p><p><strong>参考</strong></p><p><a href="https://www.bilibili.com/read/cv9248283/">https://www.bilibili.com/read/cv9248283/</a></p><p><a href="https://www.bilibili.com/video/BV13U4y1T7VS">https://www.bilibili.com/video/BV13U4y1T7VS</a></p><h3 id="2-2-基于-FTP-将GitHub图床迁移至又拍云">2.2 基于 FTP 将GitHub图床迁移至又拍云<a class="header-anchor" href="#2-2-基于-FTP-将GitHub图床迁移至又拍云"></a></h3><p><strong>参考</strong></p><p><a href="https://techs.upyun.com/videos/cdnpage/creating_storage.html">官方视频教程 - 创建存储服务和使用 FTP 上传</a>可以得到用户名和密码</p><p>默认已经完成了又拍云云存储服务的申请 + 绑定自定义域名 <a href="https://help.upyun.com/knowledge-base/quick_start/">https://help.upyun.com/knowledge-base/quick_start/</a></p><p><strong>2.2.1</strong> 编写 Python 脚本 实现批量</p><p>源码来自<a href="http://blog.csdn.net/ouyang_peng/article/details/79271113">http://blog.csdn.net/ouyang_peng/article/details/79271113</a></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> cmath <span class="keyword">import</span> log</span><br><span class="line"><span class="keyword">from</span> ftplib <span class="keyword">import</span> FTP</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line"><span class="keyword">import</span> subprocess</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">MyFTP</span>:</span><br><span class="line"> <span class="string">"""</span></span><br><span class="line"><span class="string"> ftp自动下载、自动上传脚本,可以递归目录操作</span></span><br><span class="line"><span class="string"> 作者:欧阳鹏</span></span><br><span class="line"><span class="string"> 博客地址:http://blog.csdn.net/ouyang_peng/article/details/79271113</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, host, port=<span class="number">21</span></span>):</span><br><span class="line"> <span class="string">""" 初始化 FTP 客户端</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> host:ip地址</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> port:端口号</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="comment"># print("__init__()---> host = %s ,port = %s" % (host, port))</span></span><br><span class="line"></span><br><span class="line"> self.host = host</span><br><span class="line"> self.port = port</span><br><span class="line"> self.ftp = FTP()</span><br><span class="line"> <span class="comment"># 重新设置下编码方式</span></span><br><span class="line"> <span class="comment">#self.ftp.encoding = 'gbk'</span></span><br><span class="line"> self.ftp.encoding = <span class="string">'utf8'</span></span><br><span class="line"> <span class="comment"># 获取脚本路径</span></span><br><span class="line"> path = os.path.dirname(os.path.realpath(__file__))</span><br><span class="line"> self.log_file = <span class="built_in">open</span>(path + <span class="string">"/log.txt"</span>, <span class="string">"a"</span>, encoding=<span class="string">'utf-8'</span>)</span><br><span class="line"> self.file_list = []</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">login</span>(<span class="params">self, username, password</span>):</span><br><span class="line"> <span class="string">""" 初始化 FTP 客户端</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> username: 用户名</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> password: 密码</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> timeout = <span class="number">60</span></span><br><span class="line"> socket.setdefaulttimeout(timeout)</span><br><span class="line"> <span class="comment"># 0主动模式 1 #被动模式</span></span><br><span class="line"> self.ftp.set_pasv(<span class="literal">True</span>)</span><br><span class="line"> <span class="comment"># 打开调试级别2,显示详细信息</span></span><br><span class="line"> <span class="comment"># self.ftp.set_debuglevel(2)</span></span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'开始尝试连接到 %s'</span> % self.host)</span><br><span class="line"> self.ftp.connect(self.host, self.port)</span><br><span class="line"> self.debug_print(<span class="string">'成功连接到 %s'</span> % self.host)</span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'开始尝试登录到 %s'</span> % self.host)</span><br><span class="line"> self.ftp.login(username, password)</span><br><span class="line"> self.debug_print(<span class="string">'成功登录到 %s'</span> % self.host)</span><br><span class="line"></span><br><span class="line"> self.debug_print(self.ftp.welcome)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.deal_error(<span class="string">"FTP 连接或登录失败 ,错误描述为:%s"</span> % err)</span><br><span class="line"> <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">is_same_size</span>(<span class="params">self, local_file, remote_file</span>):</span><br><span class="line"> <span class="string">"""判断远程文件和本地文件大小是否一致</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_file: 本地文件</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_file: 远程文件</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> remote_file_size = self.ftp.size(remote_file)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> <span class="comment"># self.debug_print("is_same_size() 错误描述为:%s" % err)</span></span><br><span class="line"> remote_file_size = -<span class="number">1</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> local_file_size = os.path.getsize(local_file)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> <span class="comment"># self.debug_print("is_same_size() 错误描述为:%s" % err)</span></span><br><span class="line"> local_file_size = -<span class="number">1</span></span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'local_file_size:%d , remote_file_size:%d'</span> % (local_file_size, remote_file_size))</span><br><span class="line"> <span class="keyword">if</span> remote_file_size == local_file_size:</span><br><span class="line"> <span class="keyword">return</span> <span class="number">1</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">download_file</span>(<span class="params">self, local_file, remote_file</span>):</span><br><span class="line"> <span class="string">"""从ftp下载文件</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_file: 本地文件</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_file: 远程文件</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> self.debug_print(<span class="string">"download_file()---> local_path = %s ,remote_path = %s"</span> % (local_file, remote_file))</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> self.is_same_size(local_file, remote_file):</span><br><span class="line"> self.debug_print(<span class="string">'%s 文件大小相同,无需下载'</span> % local_file)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> self.debug_print(<span class="string">'>>>>>>>>>>>>下载文件 %s ... ...'</span> % local_file)</span><br><span class="line"> buf_size = <span class="number">1024</span></span><br><span class="line"> file_handler = <span class="built_in">open</span>(local_file, <span class="string">'wb'</span>)</span><br><span class="line"> self.ftp.retrbinary(<span class="string">'RETR %s'</span> % remote_file, file_handler.write, buf_size)</span><br><span class="line"> file_handler.close()</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.debug_print(<span class="string">'下载文件出错,出现异常:%s '</span> % err)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">download_file_tree</span>(<span class="params">self, local_path, remote_path</span>):</span><br><span class="line"> <span class="string">"""从远程目录下载多个文件到本地目录</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_path: 本地路径</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_path: 远程路径</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"download_file_tree()---> local_path = %s ,remote_path = %s"</span> % (local_path, remote_path))</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> self.ftp.cwd(remote_path)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.debug_print(<span class="string">'远程目录%s不存在,继续...'</span> % remote_path + <span class="string">" ,具体错误描述为:%s"</span> % err)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> os.path.isdir(local_path):</span><br><span class="line"> self.debug_print(<span class="string">'本地目录%s不存在,先创建本地目录'</span> % local_path)</span><br><span class="line"> os.makedirs(local_path)</span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'切换至目录: %s'</span> % self.ftp.pwd())</span><br><span class="line"></span><br><span class="line"> self.file_list = []</span><br><span class="line"> <span class="comment"># 方法回调</span></span><br><span class="line"> self.ftp.<span class="built_in">dir</span>(self.get_file_list)</span><br><span class="line"></span><br><span class="line"> remote_names = self.file_list</span><br><span class="line"> self.debug_print(<span class="string">'远程目录 列表: %s'</span> % remote_names)</span><br><span class="line"> <span class="keyword">for</span> item <span class="keyword">in</span> remote_names:</span><br><span class="line"> file_type = item[<span class="number">0</span>]</span><br><span class="line"> file_name = item[<span class="number">1</span>]</span><br><span class="line"> local = os.path.join(local_path, file_name)</span><br><span class="line"> <span class="keyword">if</span> file_type == <span class="string">'d'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"download_file_tree()---> 下载目录: %s"</span> % file_name)</span><br><span class="line"> self.download_file_tree(local, file_name)</span><br><span class="line"> <span class="keyword">elif</span> file_type == <span class="string">'-'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"download_file()---> 下载文件: %s"</span> % file_name)</span><br><span class="line"> self.download_file(local, file_name)</span><br><span class="line"> self.ftp.cwd(<span class="string">".."</span>)</span><br><span class="line"> self.debug_print(<span class="string">'返回上层目录 %s'</span> % self.ftp.pwd())</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">upload_file</span>(<span class="params">self, local_file, remote_file</span>):</span><br><span class="line"> <span class="string">"""从本地上传文件到ftp</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_path: 本地文件</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_path: 远程文件</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> os.path.isfile(local_file):</span><br><span class="line"> self.debug_print(<span class="string">'%s 不存在'</span> % local_file)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> self.is_same_size(local_file, remote_file):</span><br><span class="line"> self.debug_print(<span class="string">'跳过相等的文件: %s'</span> % local_file)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> buf_size = <span class="number">1024</span></span><br><span class="line"> file_handler = <span class="built_in">open</span>(local_file, <span class="string">'rb'</span>)</span><br><span class="line"> self.ftp.storbinary(<span class="string">'STOR %s'</span> % remote_file, file_handler, buf_size)</span><br><span class="line"> file_handler.close()</span><br><span class="line"> self.debug_print(<span class="string">'上传: %s'</span> % local_file + <span class="string">"成功!"</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">upload_file_tree</span>(<span class="params">self, local_path, remote_path</span>):</span><br><span class="line"> <span class="string">"""从本地上传目录下多个文件到ftp</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> local_path: 本地路径</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_path: 远程路径</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> os.path.isdir(local_path):</span><br><span class="line"> self.debug_print(<span class="string">'本地目录 %s 不存在'</span> % local_path)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> self.ftp.cwd(remote_path)</span><br><span class="line"> self.debug_print(<span class="string">'切换至远程目录: %s'</span> % self.ftp.pwd())</span><br><span class="line"></span><br><span class="line"> local_name_list = os.listdir(local_path)</span><br><span class="line"> <span class="keyword">for</span> local_name <span class="keyword">in</span> local_name_list:</span><br><span class="line"> src = os.path.join(local_path, local_name)</span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(src):</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> self.ftp.mkd(local_name)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.debug_print(<span class="string">"目录已存在 %s ,具体错误描述为:%s"</span> % (local_name, err))</span><br><span class="line"> self.debug_print(<span class="string">"upload_file_tree()---> 上传目录: %s"</span> % local_name)</span><br><span class="line"> self.upload_file_tree(src, local_name)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> self.debug_print(<span class="string">"upload_file_tree()---> 上传文件: %s"</span> % local_name)</span><br><span class="line"> self.upload_file(src, local_name)</span><br><span class="line"> self.ftp.cwd(<span class="string">".."</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">close</span>(<span class="params">self</span>):</span><br><span class="line"> <span class="string">""" 退出ftp</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> self.debug_print(<span class="string">"close()---> FTP退出"</span>)</span><br><span class="line"> self.ftp.quit()</span><br><span class="line"> self.log_file.close()</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">debug_print</span>(<span class="params">self, s</span>):</span><br><span class="line"> <span class="string">""" 打印日志</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> self.write_log(s)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">deal_error</span>(<span class="params">self, e</span>):</span><br><span class="line"> <span class="string">""" 处理错误异常</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> e:异常</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> log_str = <span class="string">'发生错误: %s'</span> % e</span><br><span class="line"> self.write_log(log_str)</span><br><span class="line"> sys.exit()</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">write_log</span>(<span class="params">self, log_str</span>):</span><br><span class="line"> <span class="string">""" 记录日志</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> log_str:日志</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> time_now = time.localtime()</span><br><span class="line"> date_now = time.strftime(<span class="string">'%Y-%m-%d'</span>, time_now)</span><br><span class="line"> format_log_str = <span class="string">"%s ---> %s \n "</span> % (date_now, log_str)</span><br><span class="line"> <span class="built_in">print</span>(format_log_str)</span><br><span class="line"> self.log_file.write(format_log_str)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">get_file_list</span>(<span class="params">self, line</span>):</span><br><span class="line"> <span class="string">""" 获取文件列表</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> line:</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> file_arr = self.get_file_name(line)</span><br><span class="line"> <span class="comment"># 去除 . 和 ..</span></span><br><span class="line"> <span class="keyword">if</span> file_arr[<span class="number">1</span>] <span class="keyword">not</span> <span class="keyword">in</span> [<span class="string">'.'</span>, <span class="string">'..'</span>]:</span><br><span class="line"> self.file_list.append(file_arr)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">get_file_name</span>(<span class="params">self, line</span>):</span><br><span class="line"> <span class="string">""" 获取文件名</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> line:</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> pos = line.rfind(<span class="string">':'</span>)</span><br><span class="line"> <span class="keyword">while</span> (line[pos] != <span class="string">' '</span>):</span><br><span class="line"> pos += <span class="number">1</span></span><br><span class="line"> <span class="keyword">while</span> (line[pos] == <span class="string">' '</span>):</span><br><span class="line"> pos += <span class="number">1</span></span><br><span class="line"> file_arr = [line[<span class="number">0</span>], line[pos:]]</span><br><span class="line"> <span class="keyword">return</span> file_arr</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line"> <span class="comment"># 清除日志</span></span><br><span class="line"> path = os.path.dirname(os.path.realpath(__file__)) <span class="comment"># 脚本路径</span></span><br><span class="line"> <span class="keyword">if</span> os.path.exists(path + <span class="string">'/log.txt'</span>):</span><br><span class="line"> log_file = path + <span class="string">'/log.txt '</span><span class="keyword">if</span> os.sep == <span class="string">"/"</span> <span class="keyword">else</span> path + <span class="string">'\\'</span> + <span class="string">'log.txt'</span></span><br><span class="line"> subprocess.Popen(<span class="string">f'rm -rf <span class="subst">{log_file}</span>'</span>, shell=<span class="literal">True</span>)</span><br><span class="line"> time.sleep(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"> my_ftp = MyFTP(<span class="string">"xxx.ftp.upyun.com"</span>)</span><br><span class="line"> my_ftp.login(<span class="string">"xxx/xxx"</span>, <span class="string">"xxx"</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="comment"># 下载单个文件</span></span><br><span class="line"> <span class="comment"># my_ftp.download_file("E:/code_zone/image_bed/image/wallpaper/1.jpg", "/image/wallpaper/1.jpg")</span></span><br><span class="line"></span><br><span class="line"> <span class="comment"># 上传单个文件</span></span><br><span class="line"> <span class="comment"># my_ftp.upload_file("G:/ftp_test/Release/XTCLauncher.apk", "/App/AutoUpload/ouyangpeng/I12/Release/XTCLauncher.apk")</span></span><br><span class="line"></span><br><span class="line"> <span class="comment"># 下载目录</span></span><br><span class="line"> <span class="comment"># image.cpen.top/image/ → 本地 E:/code_zone/image_bed/image/ (本地图床目录, 又拍云路径)</span></span><br><span class="line"> <span class="keyword">if</span> os.sep == <span class="string">"\\"</span>:</span><br><span class="line"> my_ftp.download_file_tree(<span class="string">"E:/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>)</span><br><span class="line"> <span class="keyword">elif</span> os.sep == <span class="string">"/"</span>: <span class="comment"># aliyun</span></span><br><span class="line"> my_ftp.download_file_tree(<span class="string">"/root/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 上传目录</span></span><br><span class="line"> <span class="comment"># 本地 E:/code_zone/image_bed/image/ → image.cpen.top/image/ (本地图床目录, 又拍云路径)</span></span><br><span class="line"> <span class="keyword">if</span> os.sep == <span class="string">"\\"</span>: <span class="comment"># Windows</span></span><br><span class="line"> my_ftp.upload_file_tree(<span class="string">"E:/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>) </span><br><span class="line"> my_ftp.close()</span><br><span class="line"> <span class="keyword">elif</span> os.sep == <span class="string">"/"</span>: <span class="comment"># aliyun</span></span><br><span class="line"> my_ftp.upload_file_tree(<span class="string">"/root/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>) </span><br><span class="line"> my_ftp.close()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 命令</span></span><br><span class="line"><span class="comment"># python E:/code_zone/tools/python-ftp/ftp.py</span></span><br><span class="line"><span class="comment"># python3 /root/code_zone/tools/python-ftp/ftp.py</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p><strong>2.2.2</strong> 说明</p><p><code>my_ftp.login("用户名xxx/xxx", "密码xxx")</code> 参考 <a href="https://techs.upyun.com/videos/cdnpage/creating_storage.html">https://techs.upyun.com/videos/cdnpage/creating_storage.html</a></p><p>后期又将脚本传到云服务器上,通过计划任务,每15分钟同步,保持 GitHub 与又拍云图床一致</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># root @ CentOS in ~ [18:05:59]</span></span><br><span class="line">$ crontab -l</span><br><span class="line">*/15 * * * * <span class="built_in">cd</span> /root/code_zone/image_bed/; git pull; python3 /root/code_zone/tools/python-ftp/ftp.py; bash git.sh</span><br></pre></td></tr></table></figure><p>迁移好图床后,博客中调用图片资源时 浏览器自动 http 跳 https,因为没有证书导致图片失效,于是又申请了 ssl 证书,上传至又拍云。</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220910180219146.png" alt=""></p></blockquote><h3 id="2-3-编写批量修改文章内容的脚本">2.3 编写批量修改文章内容的脚本<a class="header-anchor" href="#2-3-编写批量修改文章内容的脚本"></a></h3><p>源码参考<a href="https://blog.csdn.net/qq_38150250/article/details/118026219">https://blog.csdn.net/qq_38150250/article/details/118026219</a></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 源码参考 https://blog.csdn.net/qq_38150250/article/details/118026219</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"></span><br><span class="line"><span class="comment"># 文件查找 find . -name file_name -type f</span></span><br><span class="line"><span class="comment"># 查找函数:search_path 查找根路径 </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取文章路径</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">search</span>(<span class="params">search_path, search_result</span>):</span><br><span class="line"> <span class="comment"># 获取当前路径下地所有文件</span></span><br><span class="line"> all_file = os.listdir(search_path)</span><br><span class="line"> <span class="comment"># 对于每一个文件</span></span><br><span class="line"> <span class="keyword">for</span> each_file <span class="keyword">in</span> all_file:</span><br><span class="line"> <span class="comment"># 若文件为一个文件夹</span></span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(search_path + each_file):</span><br><span class="line"> <span class="comment"># 递归查找</span></span><br><span class="line"> search(search_path + each_file + <span class="string">'/'</span>, search_result)</span><br><span class="line"> <span class="comment"># 如果是需要被查找的文件</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">if</span> re.findall(<span class="string">'.*\.md$'</span>, each_file) == [each_file]:</span><br><span class="line"> <span class="comment"># 输出路径</span></span><br><span class="line"> search_result.append(search_path + each_file)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 sed -i 's/old_str/new_str/'</span></span><br><span class="line"><span class="comment"># 文本替换 replace_file_name 需要替换的文件路径,replace_old_str 要替换的字符,replace_new_str 替换的字符</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">replace</span>(<span class="params">replace_file_name, replace_old_str, replace_new_str</span>):</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"r"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f1: </span><br><span class="line"> content = f1.read()</span><br><span class="line"> f1.close()</span><br><span class="line"> t = content.replace(replace_old_str, replace_new_str)</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"w"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f2:</span><br><span class="line"> f2.write(t)</span><br><span class="line"> f2.close()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 需要改的地方</span></span><br><span class="line"><span class="comment">#path = 'E:/code_zone/.history/20220831_blog/source/_posts/'</span></span><br><span class="line">path_list = [</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source/source/_posts/'</span>,</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source-butterfly/source/_posts/'</span>,</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source-diary/source/_posts/'</span>,</span><br><span class="line">]</span><br><span class="line">old_str = <span class="string">'https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fyunetadxq/image/'</span></span><br><span class="line">new_str = <span class="string">'https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fyunetadxq/image/'</span></span><br><span class="line">search_result = []</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> result = [] <span class="comment"># 存放文件路径</span></span><br><span class="line"> <span class="comment"># 默认当前目录</span></span><br><span class="line"> <span class="comment"># path = os.getcwd()</span></span><br><span class="line"> <span class="keyword">for</span> path <span class="keyword">in</span> path_list:</span><br><span class="line"> search(path, result) <span class="comment"># 获取文章路径</span></span><br><span class="line"> count = <span class="number">0</span></span><br><span class="line"> <span class="keyword">for</span> file_name <span class="keyword">in</span> result:</span><br><span class="line"> replace(file_name, old_str, new_str)</span><br><span class="line"> count += <span class="number">1</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"{} done {}"</span>.<span class="built_in">format</span>(file_name, count))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 命令</span></span><br><span class="line"><span class="comment"># python E:/code_zone/tools/python-replace/replace.py</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p><strong>2.3.1</strong> 说明</p><p><code>search</code>函数指定文件类型为 .md,可获得文章的完整路径;</p><p><code>path_list</code>列表存放需要修改的文章父目录路径,可以递归查询子目录;</p><p><code>old_str</code>需要替换的内容</p><p><code>new_str</code>新内容</p>]]></content>
|
1019
|
+
<content type="html"><![CDATA[<h2 id="一-前言">一. 前言<a class="header-anchor" href="#一-前言"></a></h2><p>因 <a href="https://www.jsdelivr.com/">https://www.jsdelivr.com/</a> 失效,博主打算将 GitHub 托管的图床备份到其他平台。</p><p>网上看到 <a href="https://github.com/lsky-org/lsky-pro">兰空图床</a> 萌生了自建图床的念头,搭建环境要求 PHP >= 8.0.2,于是打算编译安装 PHP。</p><p>最终因服务器配置太低(1核2G)编译失败而放弃。转而投身之前已经搭建好环境的又拍云平台。</p><p>博文内容:<code>PHP-CentOS8.2 编译安装 PHP8.1.10</code> + <code>编写GitHub图床迁移至又拍云的脚本(ftp)</code> + <code>编写批量修改文章内容的脚本</code></p><h2 id="二-正文">二. 正文<a class="header-anchor" href="#二-正文"></a></h2><h3 id="2-1❤-CentOS8-2-编译安装-PHP8-1-10">2.1❤ CentOS8.2 编译安装 PHP8.1.10<a class="header-anchor" href="#2-1❤-CentOS8-2-编译安装-PHP8-1-10"></a></h3><p><strong>2.1.1</strong> PHP8 和 oniguruma 源码下载并上传至服务器 /mnt 目录</p><p><a href="https://www.php.net/distributions/php-8.1.10.tar.gz">https://www.php.net/distributions/php-8.1.10.tar.gz</a></p><p><a href="https://codeload.github.com/kkos/oniguruma/tar.gz/refs/tags/v6.9.4">https://codeload.github.com/kkos/oniguruma/tar.gz/refs/tags/v6.9.4</a></p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 解压</span></span><br><span class="line">tar xzf oniguruma-6.9.4.tar.gz</span><br><span class="line">tar xzf php-8.1.10.tar.gz</span><br></pre></td></tr></table></figure><p><strong>2.1.2</strong> 安装 PHP8 依赖包</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 2 安装 PHP8 依赖包</span></span><br><span class="line">yum -y install autoconf freetype gd libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel net-snmp-devel libjpeg-devel php-ldap openldap-devel openldap-clients freetype-devel gmp-devel libzip libzip-devel sqlite-devel automake libtool</span><br></pre></td></tr></table></figure><p><strong>2.1.3</strong> 编译 PHP8 依赖包 oniguruma</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 3.1 生成 configure</span></span><br><span class="line"><span class="built_in">cd</span> /mnt/oniguruma-6.9.4</span><br><span class="line">./autogen.sh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.2 生成编译配置文件</span></span><br><span class="line">./configure --prefix=/usr</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.3 编译并安装</span></span><br><span class="line">make && make install</span><br></pre></td></tr></table></figure><p><strong>2.1.4</strong> 编译 PHP8 主包</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 4.1 生成编译配置文件</span></span><br><span class="line"><span class="built_in">cd</span> /mnt/php-8.1.10</span><br><span class="line">./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-mysqlnd --with-mysqli --with-pdo-mysql --enable-opcache --with-pcre-jit --enable-gd --with-jpeg --with-freetype --with-gettext --with-curl --with-openssl --enable-sockets --enable-mbstring --enable-xml --with-zip --with-zlib --with-snmp --with-mhash --enable-ftp --enable-bcmath --enable-soap --enable-shmop --enable-sysvsem --enable-pcntl --with-gmp</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.2 编译并安装</span></span><br><span class="line">make && make install</span><br></pre></td></tr></table></figure><p>因为配置过低,编译失败。</p><p><strong>2.1.5</strong> 编译安装后目录</p><p>/usr/local/php</p><p><strong>参考</strong></p><p><a href="https://www.bilibili.com/read/cv9248283/">https://www.bilibili.com/read/cv9248283/</a></p><p><a href="https://www.bilibili.com/video/BV13U4y1T7VS">https://www.bilibili.com/video/BV13U4y1T7VS</a></p><h3 id="2-2-基于-FTP-将GitHub图床迁移至又拍云">2.2 基于 FTP 将GitHub图床迁移至又拍云<a class="header-anchor" href="#2-2-基于-FTP-将GitHub图床迁移至又拍云"></a></h3><p><strong>参考</strong></p><p><a href="https://techs.upyun.com/videos/cdnpage/creating_storage.html">官方视频教程 - 创建存储服务和使用 FTP 上传</a>可以得到用户名和密码</p><p>默认已经完成了又拍云云存储服务的申请 + 绑定自定义域名 <a href="https://help.upyun.com/knowledge-base/quick_start/">https://help.upyun.com/knowledge-base/quick_start/</a></p><p><strong>2.2.1</strong> 编写 Python 脚本 实现批量</p><p>源码来自<a href="http://blog.csdn.net/ouyang_peng/article/details/79271113">http://blog.csdn.net/ouyang_peng/article/details/79271113</a></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> cmath <span class="keyword">import</span> log</span><br><span class="line"><span class="keyword">from</span> ftplib <span class="keyword">import</span> FTP</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"><span class="keyword">import</span> socket</span><br><span class="line"><span class="keyword">import</span> subprocess</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">MyFTP</span>:</span><br><span class="line"> <span class="string">"""</span></span><br><span class="line"><span class="string"> ftp自动下载、自动上传脚本,可以递归目录操作</span></span><br><span class="line"><span class="string"> 作者:欧阳鹏</span></span><br><span class="line"><span class="string"> 博客地址:http://blog.csdn.net/ouyang_peng/article/details/79271113</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, host, port=<span class="number">21</span></span>):</span><br><span class="line"> <span class="string">""" 初始化 FTP 客户端</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> host:ip地址</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> port:端口号</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="comment"># print("__init__()---> host = %s ,port = %s" % (host, port))</span></span><br><span class="line"></span><br><span class="line"> self.host = host</span><br><span class="line"> self.port = port</span><br><span class="line"> self.ftp = FTP()</span><br><span class="line"> <span class="comment"># 重新设置下编码方式</span></span><br><span class="line"> <span class="comment">#self.ftp.encoding = 'gbk'</span></span><br><span class="line"> self.ftp.encoding = <span class="string">'utf8'</span></span><br><span class="line"> <span class="comment"># 获取脚本路径</span></span><br><span class="line"> path = os.path.dirname(os.path.realpath(__file__))</span><br><span class="line"> self.log_file = <span class="built_in">open</span>(path + <span class="string">"/log.txt"</span>, <span class="string">"a"</span>, encoding=<span class="string">'utf-8'</span>)</span><br><span class="line"> self.file_list = []</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">login</span>(<span class="params">self, username, password</span>):</span><br><span class="line"> <span class="string">""" 初始化 FTP 客户端</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> username: 用户名</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> password: 密码</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> timeout = <span class="number">60</span></span><br><span class="line"> socket.setdefaulttimeout(timeout)</span><br><span class="line"> <span class="comment"># 0主动模式 1 #被动模式</span></span><br><span class="line"> self.ftp.set_pasv(<span class="literal">True</span>)</span><br><span class="line"> <span class="comment"># 打开调试级别2,显示详细信息</span></span><br><span class="line"> <span class="comment"># self.ftp.set_debuglevel(2)</span></span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'开始尝试连接到 %s'</span> % self.host)</span><br><span class="line"> self.ftp.connect(self.host, self.port)</span><br><span class="line"> self.debug_print(<span class="string">'成功连接到 %s'</span> % self.host)</span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'开始尝试登录到 %s'</span> % self.host)</span><br><span class="line"> self.ftp.login(username, password)</span><br><span class="line"> self.debug_print(<span class="string">'成功登录到 %s'</span> % self.host)</span><br><span class="line"></span><br><span class="line"> self.debug_print(self.ftp.welcome)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.deal_error(<span class="string">"FTP 连接或登录失败 ,错误描述为:%s"</span> % err)</span><br><span class="line"> <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">is_same_size</span>(<span class="params">self, local_file, remote_file</span>):</span><br><span class="line"> <span class="string">"""判断远程文件和本地文件大小是否一致</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_file: 本地文件</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_file: 远程文件</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> remote_file_size = self.ftp.size(remote_file)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> <span class="comment"># self.debug_print("is_same_size() 错误描述为:%s" % err)</span></span><br><span class="line"> remote_file_size = -<span class="number">1</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> local_file_size = os.path.getsize(local_file)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> <span class="comment"># self.debug_print("is_same_size() 错误描述为:%s" % err)</span></span><br><span class="line"> local_file_size = -<span class="number">1</span></span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'local_file_size:%d , remote_file_size:%d'</span> % (local_file_size, remote_file_size))</span><br><span class="line"> <span class="keyword">if</span> remote_file_size == local_file_size:</span><br><span class="line"> <span class="keyword">return</span> <span class="number">1</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">download_file</span>(<span class="params">self, local_file, remote_file</span>):</span><br><span class="line"> <span class="string">"""从ftp下载文件</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_file: 本地文件</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_file: 远程文件</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> self.debug_print(<span class="string">"download_file()---> local_path = %s ,remote_path = %s"</span> % (local_file, remote_file))</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> self.is_same_size(local_file, remote_file):</span><br><span class="line"> self.debug_print(<span class="string">'%s 文件大小相同,无需下载'</span> % local_file)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> self.debug_print(<span class="string">'>>>>>>>>>>>>下载文件 %s ... ...'</span> % local_file)</span><br><span class="line"> buf_size = <span class="number">1024</span></span><br><span class="line"> file_handler = <span class="built_in">open</span>(local_file, <span class="string">'wb'</span>)</span><br><span class="line"> self.ftp.retrbinary(<span class="string">'RETR %s'</span> % remote_file, file_handler.write, buf_size)</span><br><span class="line"> file_handler.close()</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.debug_print(<span class="string">'下载文件出错,出现异常:%s '</span> % err)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">download_file_tree</span>(<span class="params">self, local_path, remote_path</span>):</span><br><span class="line"> <span class="string">"""从远程目录下载多个文件到本地目录</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_path: 本地路径</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_path: 远程路径</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"download_file_tree()---> local_path = %s ,remote_path = %s"</span> % (local_path, remote_path))</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> self.ftp.cwd(remote_path)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.debug_print(<span class="string">'远程目录%s不存在,继续...'</span> % remote_path + <span class="string">" ,具体错误描述为:%s"</span> % err)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> os.path.isdir(local_path):</span><br><span class="line"> self.debug_print(<span class="string">'本地目录%s不存在,先创建本地目录'</span> % local_path)</span><br><span class="line"> os.makedirs(local_path)</span><br><span class="line"></span><br><span class="line"> self.debug_print(<span class="string">'切换至目录: %s'</span> % self.ftp.pwd())</span><br><span class="line"></span><br><span class="line"> self.file_list = []</span><br><span class="line"> <span class="comment"># 方法回调</span></span><br><span class="line"> self.ftp.<span class="built_in">dir</span>(self.get_file_list)</span><br><span class="line"></span><br><span class="line"> remote_names = self.file_list</span><br><span class="line"> self.debug_print(<span class="string">'远程目录 列表: %s'</span> % remote_names)</span><br><span class="line"> <span class="keyword">for</span> item <span class="keyword">in</span> remote_names:</span><br><span class="line"> file_type = item[<span class="number">0</span>]</span><br><span class="line"> file_name = item[<span class="number">1</span>]</span><br><span class="line"> local = os.path.join(local_path, file_name)</span><br><span class="line"> <span class="keyword">if</span> file_type == <span class="string">'d'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"download_file_tree()---> 下载目录: %s"</span> % file_name)</span><br><span class="line"> self.download_file_tree(local, file_name)</span><br><span class="line"> <span class="keyword">elif</span> file_type == <span class="string">'-'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"download_file()---> 下载文件: %s"</span> % file_name)</span><br><span class="line"> self.download_file(local, file_name)</span><br><span class="line"> self.ftp.cwd(<span class="string">".."</span>)</span><br><span class="line"> self.debug_print(<span class="string">'返回上层目录 %s'</span> % self.ftp.pwd())</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">upload_file</span>(<span class="params">self, local_file, remote_file</span>):</span><br><span class="line"> <span class="string">"""从本地上传文件到ftp</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> local_path: 本地文件</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_path: 远程文件</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> os.path.isfile(local_file):</span><br><span class="line"> self.debug_print(<span class="string">'%s 不存在'</span> % local_file)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span> self.is_same_size(local_file, remote_file):</span><br><span class="line"> self.debug_print(<span class="string">'跳过相等的文件: %s'</span> % local_file)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> buf_size = <span class="number">1024</span></span><br><span class="line"> file_handler = <span class="built_in">open</span>(local_file, <span class="string">'rb'</span>)</span><br><span class="line"> self.ftp.storbinary(<span class="string">'STOR %s'</span> % remote_file, file_handler, buf_size)</span><br><span class="line"> file_handler.close()</span><br><span class="line"> self.debug_print(<span class="string">'上传: %s'</span> % local_file + <span class="string">"成功!"</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">upload_file_tree</span>(<span class="params">self, local_path, remote_path</span>):</span><br><span class="line"> <span class="string">"""从本地上传目录下多个文件到ftp</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> local_path: 本地路径</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string"> remote_path: 远程路径</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> os.path.isdir(local_path):</span><br><span class="line"> self.debug_print(<span class="string">'本地目录 %s 不存在'</span> % local_path)</span><br><span class="line"> <span class="keyword">return</span></span><br><span class="line"></span><br><span class="line"> self.ftp.cwd(remote_path)</span><br><span class="line"> self.debug_print(<span class="string">'切换至远程目录: %s'</span> % self.ftp.pwd())</span><br><span class="line"></span><br><span class="line"> local_name_list = os.listdir(local_path)</span><br><span class="line"> <span class="keyword">for</span> local_name <span class="keyword">in</span> local_name_list:</span><br><span class="line"> src = os.path.join(local_path, local_name)</span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(src):</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> self.ftp.mkd(local_name)</span><br><span class="line"> <span class="keyword">except</span> Exception <span class="keyword">as</span> err:</span><br><span class="line"> self.debug_print(<span class="string">"目录已存在 %s ,具体错误描述为:%s"</span> % (local_name, err))</span><br><span class="line"> self.debug_print(<span class="string">"upload_file_tree()---> 上传目录: %s"</span> % local_name)</span><br><span class="line"> self.upload_file_tree(src, local_name)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> self.debug_print(<span class="string">"upload_file_tree()---> 上传文件: %s"</span> % local_name)</span><br><span class="line"> self.upload_file(src, local_name)</span><br><span class="line"> self.ftp.cwd(<span class="string">".."</span>)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">close</span>(<span class="params">self</span>):</span><br><span class="line"> <span class="string">""" 退出ftp</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> self.debug_print(<span class="string">"close()---> FTP退出"</span>)</span><br><span class="line"> self.ftp.quit()</span><br><span class="line"> self.log_file.close()</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">debug_print</span>(<span class="params">self, s</span>):</span><br><span class="line"> <span class="string">""" 打印日志</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> self.write_log(s)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">deal_error</span>(<span class="params">self, e</span>):</span><br><span class="line"> <span class="string">""" 处理错误异常</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> e:异常</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> log_str = <span class="string">'发生错误: %s'</span> % e</span><br><span class="line"> self.write_log(log_str)</span><br><span class="line"> sys.exit()</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">write_log</span>(<span class="params">self, log_str</span>):</span><br><span class="line"> <span class="string">""" 记录日志</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> log_str:日志</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> time_now = time.localtime()</span><br><span class="line"> date_now = time.strftime(<span class="string">'%Y-%m-%d'</span>, time_now)</span><br><span class="line"> format_log_str = <span class="string">"%s ---> %s \n "</span> % (date_now, log_str)</span><br><span class="line"> <span class="built_in">print</span>(format_log_str)</span><br><span class="line"> self.log_file.write(format_log_str)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">get_file_list</span>(<span class="params">self, line</span>):</span><br><span class="line"> <span class="string">""" 获取文件列表</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> line:</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> file_arr = self.get_file_name(line)</span><br><span class="line"> <span class="comment"># 去除 . 和 ..</span></span><br><span class="line"> <span class="keyword">if</span> file_arr[<span class="number">1</span>] <span class="keyword">not</span> <span class="keyword">in</span> [<span class="string">'.'</span>, <span class="string">'..'</span>]:</span><br><span class="line"> self.file_list.append(file_arr)</span><br><span class="line"></span><br><span class="line"> <span class="keyword">def</span> <span class="title function_">get_file_name</span>(<span class="params">self, line</span>):</span><br><span class="line"> <span class="string">""" 获取文件名</span></span><br><span class="line"><span class="string"> 参数:</span></span><br><span class="line"><span class="string"> line:</span></span><br><span class="line"><span class="string"> """</span></span><br><span class="line"> pos = line.rfind(<span class="string">':'</span>)</span><br><span class="line"> <span class="keyword">while</span> (line[pos] != <span class="string">' '</span>):</span><br><span class="line"> pos += <span class="number">1</span></span><br><span class="line"> <span class="keyword">while</span> (line[pos] == <span class="string">' '</span>):</span><br><span class="line"> pos += <span class="number">1</span></span><br><span class="line"> file_arr = [line[<span class="number">0</span>], line[pos:]]</span><br><span class="line"> <span class="keyword">return</span> file_arr</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line"> <span class="comment"># 清除日志</span></span><br><span class="line"> path = os.path.dirname(os.path.realpath(__file__)) <span class="comment"># 脚本路径</span></span><br><span class="line"> <span class="keyword">if</span> os.path.exists(path + <span class="string">'/log.txt'</span>):</span><br><span class="line"> log_file = path + <span class="string">'/log.txt '</span><span class="keyword">if</span> os.sep == <span class="string">"/"</span> <span class="keyword">else</span> path + <span class="string">'\\'</span> + <span class="string">'log.txt'</span></span><br><span class="line"> subprocess.Popen(<span class="string">f'rm -rf <span class="subst">{log_file}</span>'</span>, shell=<span class="literal">True</span>)</span><br><span class="line"> time.sleep(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"> my_ftp = MyFTP(<span class="string">"xxx.ftp.upyun.com"</span>)</span><br><span class="line"> my_ftp.login(<span class="string">"xxx/xxx"</span>, <span class="string">"xxx"</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> <span class="comment"># 下载单个文件</span></span><br><span class="line"> <span class="comment"># my_ftp.download_file("E:/code_zone/image_bed/image/wallpaper/1.jpg", "/image/wallpaper/1.jpg")</span></span><br><span class="line"></span><br><span class="line"> <span class="comment"># 上传单个文件</span></span><br><span class="line"> <span class="comment"># my_ftp.upload_file("G:/ftp_test/Release/XTCLauncher.apk", "/App/AutoUpload/ouyangpeng/I12/Release/XTCLauncher.apk")</span></span><br><span class="line"></span><br><span class="line"> <span class="comment"># 下载目录</span></span><br><span class="line"> <span class="comment"># image.cpen.top/image/ → 本地 E:/code_zone/image_bed/image/ (本地图床目录, 又拍云路径)</span></span><br><span class="line"> <span class="keyword">if</span> os.sep == <span class="string">"\\"</span>:</span><br><span class="line"> my_ftp.download_file_tree(<span class="string">"E:/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>)</span><br><span class="line"> <span class="keyword">elif</span> os.sep == <span class="string">"/"</span>: <span class="comment"># aliyun</span></span><br><span class="line"> my_ftp.download_file_tree(<span class="string">"/root/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>)</span><br><span class="line"></span><br><span class="line"> <span class="comment"># 上传目录</span></span><br><span class="line"> <span class="comment"># 本地 E:/code_zone/image_bed/image/ → image.cpen.top/image/ (本地图床目录, 又拍云路径)</span></span><br><span class="line"> <span class="keyword">if</span> os.sep == <span class="string">"\\"</span>: <span class="comment"># Windows</span></span><br><span class="line"> my_ftp.upload_file_tree(<span class="string">"E:/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>) </span><br><span class="line"> my_ftp.close()</span><br><span class="line"> <span class="keyword">elif</span> os.sep == <span class="string">"/"</span>: <span class="comment"># aliyun</span></span><br><span class="line"> my_ftp.upload_file_tree(<span class="string">"/root/code_zone/image_bed/image/"</span>, <span class="string">"/image/"</span>) </span><br><span class="line"> my_ftp.close()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 命令</span></span><br><span class="line"><span class="comment"># python E:/code_zone/tools/python-ftp/ftp.py</span></span><br><span class="line"><span class="comment"># python3 /root/code_zone/tools/python-ftp/ftp.py</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p><strong>2.2.2</strong> 说明</p><p><code>my_ftp.login("用户名xxx/xxx", "密码xxx")</code> 参考 <a href="https://techs.upyun.com/videos/cdnpage/creating_storage.html">https://techs.upyun.com/videos/cdnpage/creating_storage.html</a></p><p>后期又将脚本传到云服务器上,通过计划任务,每15分钟同步,保持 GitHub 与又拍云图床一致</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># root @ CentOS in ~ [18:05:59]</span></span><br><span class="line">$ crontab -l</span><br><span class="line">*/15 * * * * <span class="built_in">cd</span> /root/code_zone/image_bed/; git pull; python3 /root/code_zone/tools/python-ftp/ftp.py; bash git.sh</span><br></pre></td></tr></table></figure><p>迁移好图床后,博客中调用图片资源时 浏览器自动 http 跳 https,因为没有证书导致图片失效,于是又申请了 ssl 证书,上传至又拍云。</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220910180219146.png" alt=""></p></blockquote><h3 id="2-3-编写批量修改文章内容的脚本">2.3 编写批量修改文章内容的脚本<a class="header-anchor" href="#2-3-编写批量修改文章内容的脚本"></a></h3><p>源码参考<a href="https://blog.csdn.net/qq_38150250/article/details/118026219">https://blog.csdn.net/qq_38150250/article/details/118026219</a></p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/python</span></span><br><span class="line"><span class="comment"># -*- coding: UTF-8 -*-</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 源码参考 https://blog.csdn.net/qq_38150250/article/details/118026219</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"></span><br><span class="line"><span class="comment"># 文件查找 find . -name file_name -type f</span></span><br><span class="line"><span class="comment"># 查找函数:search_path 查找根路径 </span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取文章路径</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">search</span>(<span class="params">search_path, search_result</span>):</span><br><span class="line"> <span class="comment"># 获取当前路径下地所有文件</span></span><br><span class="line"> all_file = os.listdir(search_path)</span><br><span class="line"> <span class="comment"># 对于每一个文件</span></span><br><span class="line"> <span class="keyword">for</span> each_file <span class="keyword">in</span> all_file:</span><br><span class="line"> <span class="comment"># 若文件为一个文件夹</span></span><br><span class="line"> <span class="keyword">if</span> os.path.isdir(search_path + each_file):</span><br><span class="line"> <span class="comment"># 递归查找</span></span><br><span class="line"> search(search_path + each_file + <span class="string">'/'</span>, search_result)</span><br><span class="line"> <span class="comment"># 如果是需要被查找的文件</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">if</span> re.findall(<span class="string">'.*\.md$'</span>, each_file) == [each_file]:</span><br><span class="line"> <span class="comment"># 输出路径</span></span><br><span class="line"> search_result.append(search_path + each_file)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 替换 sed -i 's/old_str/new_str/'</span></span><br><span class="line"><span class="comment"># 文本替换 replace_file_name 需要替换的文件路径,replace_old_str 要替换的字符,replace_new_str 替换的字符</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">replace</span>(<span class="params">replace_file_name, replace_old_str, replace_new_str</span>):</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"r"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f1: </span><br><span class="line"> content = f1.read()</span><br><span class="line"> f1.close()</span><br><span class="line"> t = content.replace(replace_old_str, replace_new_str)</span><br><span class="line"> <span class="keyword">with</span> <span class="built_in">open</span>(replace_file_name, <span class="string">"w"</span>, encoding = <span class="string">"UTF-8"</span>) <span class="keyword">as</span> f2:</span><br><span class="line"> f2.write(t)</span><br><span class="line"> f2.close()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 需要改的地方</span></span><br><span class="line"><span class="comment">#path = 'E:/code_zone/.history/20220831_blog/source/_posts/'</span></span><br><span class="line">path_list = [</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source/source/_posts/'</span>,</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source-butterfly/source/_posts/'</span>,</span><br><span class="line"> <span class="string">'E:/code_zone/hexo-source-diary/source/_posts/'</span>,</span><br><span class="line">]</span><br><span class="line">old_str = <span class="string">'https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/'</span></span><br><span class="line">new_str = <span class="string">'https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/'</span></span><br><span class="line">search_result = []</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> result = [] <span class="comment"># 存放文件路径</span></span><br><span class="line"> <span class="comment"># 默认当前目录</span></span><br><span class="line"> <span class="comment"># path = os.getcwd()</span></span><br><span class="line"> <span class="keyword">for</span> path <span class="keyword">in</span> path_list:</span><br><span class="line"> search(path, result) <span class="comment"># 获取文章路径</span></span><br><span class="line"> count = <span class="number">0</span></span><br><span class="line"> <span class="keyword">for</span> file_name <span class="keyword">in</span> result:</span><br><span class="line"> replace(file_name, old_str, new_str)</span><br><span class="line"> count += <span class="number">1</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"{} done {}"</span>.<span class="built_in">format</span>(file_name, count))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 命令</span></span><br><span class="line"><span class="comment"># python E:/code_zone/tools/python-replace/replace.py</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><p><strong>2.3.1</strong> 说明</p><p><code>search</code>函数指定文件类型为 .md,可获得文章的完整路径;</p><p><code>path_list</code>列表存放需要修改的文章父目录路径,可以递归查询子目录;</p><p><code>old_str</code>需要替换的内容</p><p><code>new_str</code>新内容</p>]]></content>
|
1020
1020
|
|
1021
1021
|
|
1022
1022
|
<categories>
|
@@ -1518,7 +1518,7 @@
|
|
1518
1518
|
<link href="/posts/8236.html"/>
|
1519
1519
|
<url>/posts/8236.html</url>
|
1520
1520
|
|
1521
|
-
<content type="html"><![CDATA[<h1 id="Hexo-搭建私人博客">Hexo 搭建私人博客<a class="header-anchor" href="#Hexo-搭建私人博客"></a></h1><h2 id="一-介绍">一. 介绍<a class="header-anchor" href="#一-介绍"></a></h2><h3 id="1-1-Hexo">1.1 Hexo<a class="header-anchor" href="#1-1-Hexo"></a></h3><blockquote><p>Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 <a href="http://daringfireball.net/projects/markdown/">Markdown</a>(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。<a href="https://hexo.io">Hexo 官网</a></p></blockquote><h3 id="1-2-Pure-主题">1.2 Pure 主题<a class="header-anchor" href="#1-2-Pure-主题"></a></h3><p><a href="https://github.com/cofess/hexo-theme-pure">https://github.com/cofess/hexo-theme-pure</a></p><p><a href="https://blog.cofess.com/">https://blog.cofess.com/</a></p><hr><h2 id="二-参考">二. 参考<a class="header-anchor" href="#二-参考"></a></h2><p>Hexo 官网<a href="https://hexo.io/zh-cn/docs/index.html">https://hexo.io/zh-cn/docs/index.html</a></p><p>Pure 项目地址<a href="https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md">https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md</a></p><h3 id="搭建-魔改">搭建 & 魔改<a class="header-anchor" href="#搭建-魔改"></a></h3><ul class="lvl-0"><li class="lvl-2"><p><a href="https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md">Pure 项目中文文档</a></p></li><li class="lvl-2"><p><a href="https://hwame.top/20200520/hello-hexo-setup-deploy.html">https://hwame.top</a></p></li><li class="lvl-2"><p><a href="https://blog.cofess.com/2017/11/01/hexo-blog-theme-pure-usage-description.html">作者: Hexo博客主题pure使用说明</a></p></li><li class="lvl-2"><p><a href="https://www.cnblogs.com/zzk31/p/14062887.html">https://www.cnblogs.com/zzk31/p/14062887.html</a></p></li><li class="lvl-2"><p><a href="https://blog.csdn.net/qq_42983502/article/details/106745567">https://blog.csdn.net/qq_42983502/article/details/106745567</a></p></li><li class="lvl-2"><p>gitalk</p><ul class="lvl-2"><li class="lvl-4"><a href="https://www.jianshu.com/p/b1161eb3f848">https://www.jianshu.com/p/b1161eb3f848</a></li><li class="lvl-4"><a href="https://cors-anywhere.herokuapp.com/corsdemo">https://cors-anywhere.herokuapp.com/corsdemo</a></li><li class="lvl-4"><a href="https://www.cnblogs.com/qisi007/p/13731562.html">https://www.cnblogs.com/qisi007/p/13731562.html</a></li><li class="lvl-4"><a href="https://www.jianshu.com/p/02fc71f3633f">https://www.jianshu.com/p/02fc71f3633f</a></li></ul></li></ul><hr><h2 id="三-命令">三. 命令<a class="header-anchor" href="#三-命令"></a></h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo clean ; hexo g ; hexo d ; hexo s</span><br></pre></td></tr></table></figure><hr><h2 id="四-评论-收录">四. 评论 & 收录<a class="header-anchor" href="#四-评论-收录"></a></h2><p>Valine 评论<a href="https://www.leancloud.cn/">https://www.leancloud.cn/</a></p><p>Valine 评论<a href="https://www.leancloud.app/">https://www.leancloud.app/</a>国外站点,国内账号受限,域名没白嫖成功,可能是这个原因 → <a href="https://forum.leancloud.cn/t/2022-8/25408">https://forum.leancloud.cn/t/2022-8/25408</a></p><p>谷歌收录<a href="">https://search.google.com/search-console</a></p><p>百度收录<a href="https://ziyuan.baidu.com">https://ziyuan.baidu.com</a></p><p>MD5 在线加密<a href="https://md5jiami.bmcx.com/">https://md5jiami.bmcx.com/</a>评论区通过密文,识别博主身份</p><hr><h2 id="五-相关路径">五. 相关路径<a class="header-anchor" href="#五-相关路径"></a></h2><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">[<span class="symbol">文章路径</span>]: </span><br><span class="line"><span class="link">\source\_posts</span></span><br><span class="line">[<span class="symbol">站点配置文件</span>]: </span><br><span class="line"><span class="link">\_config.yml</span></span><br><span class="line">[<span class="symbol">主题配置文件</span>]: </span><br><span class="line"><span class="link">\themes\pure\_config.yml"关于、个人介绍、公告"</span></span><br><span class="line">[<span class="symbol">友链文件</span>]: </span><br><span class="line"><span class="link">\source\_data\links.yml</span></span><br><span class="line">[<span class="symbol">语言</span>]: </span><br><span class="line"><span class="link">\themes\pure\languages</span></span><br><span class="line">[<span class="symbol">左下角运行时间</span>]: </span><br><span class="line"><span class="link">\themes\pure\layout\_common\footer.ejs"时间、版权"</span></span><br><span class="line">[<span class="symbol">评论角色配置</span>]: </span><br><span class="line"><span class="link">\themes\pure\layout\_script\_comment\valine.ejs</span></span><br><span class="line">[<span class="symbol">css样式</span>]:</span><br><span class="line"><span class="link">\themes\pure\source\css\style.css</span></span><br><span class="line">[<span class="symbol">搜索栏限制</span>]: </span><br><span class="line"><span class="link">\themes\pure\source\js\insight.js"160行"</span></span><br></pre></td></tr></table></figure><hr><h2 id="六-内容样例">六. 内容样例<a class="header-anchor" href="#六-内容样例"></a></h2><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: Test</span><br><span class="line">date: 2022-08-28 00:09:00</span><br><span class="line">updated: 2022-08-28 00:09:01</span><br><span class="line">thumbnail: https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fyunetadxq/image/test.png</span><br><span class="line">tags:</span><br><span class="line"><span class="bullet"> -</span> Test</span><br><span class="line">category:</span><br><span class="line"><span class="bullet"> -</span> Test</span><br><span class="line">toc: true</span><br><span class="line"><span class="section">top: true</span></span><br><span class="line"><span class="section">---</span></span><br><span class="line">描述<!-- more --></span><br></pre></td></tr></table></figure><h3 id="文章指定多个-category">文章指定多个 category<a class="header-anchor" href="#文章指定多个-category"></a></h3><blockquote><p>多个分类</p><p>如果我们的要求是将文章同时分到两个或者多个不同的类目下呢?官方给出的方法是:</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">categories:</span><br><span class="line"> - [Sports]</span><br><span class="line"> - [Baseball]</span><br></pre></td></tr></table></figure><p>参考文章:<a href="https://www.jianshu.com/p/4438c417611e">Hexo 一篇文章多个 categories https://www.jianshu.com/p/4438c417611e</a></p></blockquote><hr><h2 id="七-自定义">七. 自定义<a class="header-anchor" href="#七-自定义"></a></h2><h3 id="7-1-搜索框索引突破-5">7.1 搜索框索引突破 5<a class="header-anchor" href="#7-1-搜索框索引突破-5"></a></h3><ol><li class="lvl-3"><p><code>F12</code> 定位到搜索框的 类选择器 为 ins-section-header</p></li><li class="lvl-3"><p>grep,定位到配置文件为 <code>\themes\pure\source\js\insight.js</code></p></li><li class="lvl-3"><p>Ctrl + F,搜索 5,定位到第 160 行,修改限制</p></li></ol><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830075511578.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830075224471.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830075722865.png" alt=""></p></blockquote><h3 id="7-2-左侧头像链接,target-修改为-self">7.2 左侧头像链接,target 修改为 _self<a class="header-anchor" href="#7-2-左侧头像链接,target-修改为-self"></a></h3><p>a 标签,修改 target: ‘_blank’ → ‘_self’</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830080811356.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830080916410.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830080945424.png" alt=""></p></blockquote><hr><h3 id="7-3-文章目录,一级标题不跳转">7.3 文章目录,一级标题不跳转<a class="header-anchor" href="#7-3-文章目录,一级标题不跳转"></a></h3><p>有时发现一级标题不会跳转</p><p><s>配置文件<code>\node_modules\hexo\lib\plugins\helper\toc.js</code></s></p><p><s>更新下 <code>\node_modules\hexo\lib\plugins\helper\toc.js</code> 文件,又正常了。时灵时不灵的。。。</s></p><p><s>参考<a href="https://hwame.top/20200520/hello-hexo-troubleshooting.html#3-%E5%A6%82%E4%BD%95%E5%8F%96%E6%B6%88%E6%96%87%E7%AB%A0%E7%9B%AE%E5%BD%95%E7%9A%84%E8%87%AA%E5%8A%A8%E7%BC%96%E5%8F%B7">https://hwame.top/如何取消文章目录的自动编号</a></s></p><p>修改 “.\node_modules\hexo-renderer-markdown-it\index.js” level 为 1</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220906033013691.png" alt=""></p></blockquote><ul class="lvl-0"><li class="lvl-2"><p>参考文章:</p><p><a href="https://blog.csdn.net/Fosu_Chenai/article/details/111192850">https://blog.csdn.net/Fosu_Chenai/article/details/111192850 评论</a></p></li></ul><hr><h3 id="7-4-滚动条加粗-加小箭头">7.4 滚动条加粗 + 加小箭头<a class="header-anchor" href="#7-4-滚动条加粗-加小箭头"></a></h3><ul class="lvl-0"><li class="lvl-2"><p>修改 css 样式,路径 <code>.\hexo-source\themes\pure\source\css\style.css</code></p><ol><li class="lvl-5"><code>Ctlrl + F</code> 定位 <code>scrollbar</code>;</li><li class="lvl-5">调高 <code>height</code>,使代码框 右拉滚动条加粗;</li><li class="lvl-5">右侧下拉条变粗;</li></ol><blockquote><p><strong>7.4.1 代码框加粗</strong></p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * scrollbar</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">15px</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">14px</span>;# 调高</span><br><span class="line"> <span class="attribute">background</span>: transparent;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901164700329.png" alt=""></p><p><strong>7.4.2 右侧下拉条变粗 + 添加小箭头</strong></p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * 滚动条箭头</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">::-webkit-scrollbar-button {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">0px</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">4px</span>;</span><br><span class="line"> <span class="attribute">display</span>: block; </span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#c3c3c3</span>;</span><br><span class="line">}</span><br><span class="line">::-webkit-scrollbar {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">16px</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">5px</span> solid white;</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-thumb {</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#b0b0b0</span>;</span><br><span class="line"> <span class="attribute">background-clip</span>: padding-box;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">0.05em</span> solid <span class="number">#eeeeee</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-track {</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#bbbbbb</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">/* Buttons */</span></span><br><span class="line">::-webkit-scrollbar-button:single-button {</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#bbbbbb</span>;</span><br><span class="line"> <span class="attribute">display</span>: block;</span><br><span class="line"> <span class="attribute">border-style</span>: solid;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">13px</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">16px</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">/* Up */</span></span><br><span class="line">::-webkit-scrollbar-button:single-button:vertical:decrement {</span><br><span class="line"> <span class="attribute">border-width</span>: <span class="number">0px</span> <span class="number">8px</span> <span class="number">8px</span> <span class="number">8px</span>;</span><br><span class="line"> <span class="attribute">border-color</span>: transparent transparent <span class="number">#555555</span> transparent;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-button:single-button:vertical:decrement:hover {</span><br><span class="line"> <span class="attribute">border-color</span>: transparent transparent <span class="number">#777777</span> transparent;</span><br><span class="line">}</span><br><span class="line"><span class="comment">/* Down */</span></span><br><span class="line">::-webkit-scrollbar-button:single-button:vertical:increment {</span><br><span class="line"> <span class="attribute">border-width</span>: <span class="number">8px</span> <span class="number">8px</span> <span class="number">0</span> <span class="number">8px</span>;</span><br><span class="line"> <span class="attribute">border-color</span>: <span class="number">#555555</span> transparent transparent transparent;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-button:vertical:single-button:increment:hover {</span><br><span class="line"> <span class="attribute">border-color</span>: <span class="number">#777777</span> transparent transparent transparent;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901164914382.png" alt=""></p></blockquote></li></ul><p><strong>参考文章</strong></p><ul class="lvl-0"><li class="lvl-2"><p><a href="http://www.qianduanheidong.com/blog/article/27901/a1c9346c7830d6ffa3f2/">右侧下拉条新增箭头</a></p></li><li class="lvl-2"><p><a href="https://www.php.cn/css-tutorial-475268.html">:-webkit-scrollbar 滚动条整体部分 https://www.php.cn/css-tutorial-475268.html</a></p></li></ul><h3 id="7-5-Valine-评论框添加一言">7.5 Valine 评论框添加一言<a class="header-anchor" href="#7-5-Valine-评论框添加一言"></a></h3><p><strong>参考文章</strong></p><ul class="lvl-0"><li class="lvl-2"><p><a href="https://blog.justlovesmile.top/posts/27831.html">https://blog.justlovesmile.top/posts/27831.html</a></p></li></ul><p>偶然看到的文章,然后自己就加了这个功能。</p><ul class="lvl-0"><li class="lvl-2"><p>路径:<code>.\themes\pure\layout\_script\_comment\valine.ejs</code>;</p></li><li class="lvl-2"><p>加到最后 <code></script></code> 标签之前;c=j 请求获得网易云的句子,开始网抑云吧;</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">fetch('https://v1.hitokoto.cn/?c=j')</span><br><span class="line">.then(response => response.json())</span><br><span class="line">.then(data => {</span><br><span class="line"> document.getElementById("veditor").setAttribute("placeholder",data.hitokoto+"__"+data.from);</span><br><span class="line">})</span><br><span class="line">.catch(console.error)</span><br></pre></td></tr></table></figure></li></ul><blockquote><p>修改方法:</p><ol><li class="lvl-3"><p>找到博客对应添加valine的位置,例如Ayer主题的位于hexo\themes\ayer\layout_partial\post\valine.ejs</p></li><li class="lvl-3"><p>在内部添加一段代码:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><script type="text/javascript"></span><br><span class="line"> fetch('https://v1.hitokoto.cn')</span><br><span class="line"> .then(response => response.json())</span><br><span class="line"> .then(data => {</span><br><span class="line"> document.getElementById("veditor").setAttribute("placeholder",data.hitokoto+"__"+data.from);</span><br><span class="line"> })</span><br><span class="line"> .catch(console.error)</span><br><span class="line"></script></span><br></pre></td></tr></table></figure></li><li class="lvl-3"><p>Api接口说明:<br>(1)<a href="https://v1.hitokoto.cn/">https://v1.hitokoto.cn/</a> (从7种分类中随机抽取)<br>(2)<a href="https://v1.hitokoto.cn/?c=b">https://v1.hitokoto.cn/?c=b</a> (请求获得一个分类是漫画的句子)<br>参数说明<br>a动画<br>b漫画<br>c游戏<br>d文学<br>e原创<br>f来自网络<br>g其他<br>h影视<br>i诗词<br>j网易云<br>k哲学<br>l抖机灵<br>其他作为动画类型处理<br>可选择多个分类,例如: ?c=a&c=c</p></li></ol><p>(3)<a href="https://v1.hitokoto.cn/?c=f&encode=text">https://v1.hitokoto.cn/?c=f&encode=text</a> (请求获得一个来自网络的句子,并以纯文本格式输出)</p><ol start="4"><li class="lvl-3"><p>返回的格式说明<br>返回参数名称描述<br>id一言标识<br>hitokoto一言正文。编码方式 unicode。使用 utf-8。<br>type类型<br>from一言的出处<br>from_who一言的作者<br>creator添加者<br>creator_uid添加者用户标识<br>reviewer审核员标识<br>uuid一言唯一标识;可以链接到 <a href="https://hitokoto.cn?uuid=%5Buuid%5D">https://hitokoto.cn?uuid=[uuid]</a> 查看这个一言的完整信息<br>commit_from提交方式<br>created_at添加时间<br>length句子长度<br>例如:返回的data,通过data.hitokoto获取句子正文</p></li></ol><p>作者: Justlovesmile<br>链接: <a href="https://blog.justlovesmile.top/posts/27831.html">https://blog.justlovesmile.top/posts/27831.html</a><br>来源: Justlovesmile’s BLOG<br>著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。</p></blockquote><p>PS:这位大佬的博客真好看~~</p><h3 id="7-6-左侧-归档、分类-改为默认收起">7.6 左侧 归档、分类 改为默认收起<a class="header-anchor" href="#7-6-左侧-归档、分类-改为默认收起"></a></h3><ul class="lvl-0"><li class="lvl-2"><p>默认是展开的</p></li></ul><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203849607.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203907981.png" alt=""></p></blockquote><ul class="lvl-0"><li class="lvl-2"><p>修改以下文件,改为收起状态。如图</p><ul class="lvl-2"><li class="lvl-4">style=“height: 0px” 应该可以不用写,收起状态默认就是 0 ~~</li></ul></li></ul><blockquote><p><code>.\themes\pure\layout\categories.ejs</code></p><p><code>.\themes\pure\layout\_partial\archive.ejs</code></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203746673.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203807739.png" alt=""></p></blockquote><hr><h2 id="八-未解决的小需求">八. 未解决的小需求<a class="header-anchor" href="#八-未解决的小需求"></a></h2><ol><li class="lvl-3"><p>(已解决,#7.3)一级目录,右侧导航栏 有时跳转失败;</p></li><li class="lvl-3"><p>Valine 评论系统,下面的评论 被@后,未显示 @信息,而别人的是成功的;</p><blockquote><p>我的</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901171817579.png" alt=""></p><p>其他大佬的</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901171912131.png" alt=""></p></blockquote></li><li class="lvl-3"><p>引用时 使用 #,会被导航目录误认为 一级标题;</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901172133945.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901172316157.png" alt=""></p></blockquote></li><li class="lvl-3"><p>(已解决)生成在 /public 目录的静态文件都被压缩了,<s>我看别人的没被压缩,不清楚啥原因。</s> 因为配置了这个 <a href="https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md#%E5%8D%9A%E5%AE%A2%E4%BC%98%E5%8C%96">https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md 博客优化</a> 压缩了文件</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901175404486.png" alt=""></p></blockquote></li><li class="lvl-3"><p>(已解决)文章内部一级、二级…标题左侧无锚点</p><blockquote><p>理想效果图</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220906034109271.png" alt=""></p><p><s>似乎是环境配置问题,我用虚拟机推送静态文件,就有显示;用真实 win机 推送 就没有锚点,重装 git 也没显示(可能不是 git 的问题)。。。</s></p><p>因为压缩了静态文件,全部注释 <code>hexo-neat</code> 配置。<br>参考<br><a href="https://github.com/cofess/hexo-theme-pure#hexo-neat">https://github.com/cofess/hexo-theme-pure#hexo-neat</a><br><a href="https://github.com/rozbo/hexo-neat#options">https://github.com/rozbo/hexo-neat#options</a></p></blockquote></li></ol><p>无伤大雅,<s>我一般一级标题写的是文章标题</s>;评论区也就是个摆设;<s>静态文件被压缩,可能别人还觉得我是故意,嘿</s>~~</p><p>最后总结:魔改要适量,太费时 还得不到提升,不如多看几个前端视频 多写几篇文章。。。</p><hr>]]></content>
|
1521
|
+
<content type="html"><![CDATA[<h1 id="Hexo-搭建私人博客">Hexo 搭建私人博客<a class="header-anchor" href="#Hexo-搭建私人博客"></a></h1><h2 id="一-介绍">一. 介绍<a class="header-anchor" href="#一-介绍"></a></h2><h3 id="1-1-Hexo">1.1 Hexo<a class="header-anchor" href="#1-1-Hexo"></a></h3><blockquote><p>Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 <a href="http://daringfireball.net/projects/markdown/">Markdown</a>(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。<a href="https://hexo.io">Hexo 官网</a></p></blockquote><h3 id="1-2-Pure-主题">1.2 Pure 主题<a class="header-anchor" href="#1-2-Pure-主题"></a></h3><p><a href="https://github.com/cofess/hexo-theme-pure">https://github.com/cofess/hexo-theme-pure</a></p><p><a href="https://blog.cofess.com/">https://blog.cofess.com/</a></p><hr><h2 id="二-参考">二. 参考<a class="header-anchor" href="#二-参考"></a></h2><p>Hexo 官网<a href="https://hexo.io/zh-cn/docs/index.html">https://hexo.io/zh-cn/docs/index.html</a></p><p>Pure 项目地址<a href="https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md">https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md</a></p><h3 id="搭建-魔改">搭建 & 魔改<a class="header-anchor" href="#搭建-魔改"></a></h3><ul class="lvl-0"><li class="lvl-2"><p><a href="https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md">Pure 项目中文文档</a></p></li><li class="lvl-2"><p><a href="https://hwame.top/20200520/hello-hexo-setup-deploy.html">https://hwame.top</a></p></li><li class="lvl-2"><p><a href="https://blog.cofess.com/2017/11/01/hexo-blog-theme-pure-usage-description.html">作者: Hexo博客主题pure使用说明</a></p></li><li class="lvl-2"><p><a href="https://www.cnblogs.com/zzk31/p/14062887.html">https://www.cnblogs.com/zzk31/p/14062887.html</a></p></li><li class="lvl-2"><p><a href="https://blog.csdn.net/qq_42983502/article/details/106745567">https://blog.csdn.net/qq_42983502/article/details/106745567</a></p></li><li class="lvl-2"><p>gitalk</p><ul class="lvl-2"><li class="lvl-4"><a href="https://www.jianshu.com/p/b1161eb3f848">https://www.jianshu.com/p/b1161eb3f848</a></li><li class="lvl-4"><a href="https://cors-anywhere.herokuapp.com/corsdemo">https://cors-anywhere.herokuapp.com/corsdemo</a></li><li class="lvl-4"><a href="https://www.cnblogs.com/qisi007/p/13731562.html">https://www.cnblogs.com/qisi007/p/13731562.html</a></li><li class="lvl-4"><a href="https://www.jianshu.com/p/02fc71f3633f">https://www.jianshu.com/p/02fc71f3633f</a></li></ul></li></ul><hr><h2 id="三-命令">三. 命令<a class="header-anchor" href="#三-命令"></a></h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hexo clean ; hexo g ; hexo d ; hexo s</span><br></pre></td></tr></table></figure><hr><h2 id="四-评论-收录">四. 评论 & 收录<a class="header-anchor" href="#四-评论-收录"></a></h2><p>Valine 评论<a href="https://www.leancloud.cn/">https://www.leancloud.cn/</a></p><p>Valine 评论<a href="https://www.leancloud.app/">https://www.leancloud.app/</a>国外站点,国内账号受限,域名没白嫖成功,可能是这个原因 → <a href="https://forum.leancloud.cn/t/2022-8/25408">https://forum.leancloud.cn/t/2022-8/25408</a></p><p>谷歌收录<a href="">https://search.google.com/search-console</a></p><p>百度收录<a href="https://ziyuan.baidu.com">https://ziyuan.baidu.com</a></p><p>MD5 在线加密<a href="https://md5jiami.bmcx.com/">https://md5jiami.bmcx.com/</a>评论区通过密文,识别博主身份</p><hr><h2 id="五-相关路径">五. 相关路径<a class="header-anchor" href="#五-相关路径"></a></h2><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">[<span class="symbol">文章路径</span>]: </span><br><span class="line"><span class="link">\source\_posts</span></span><br><span class="line">[<span class="symbol">站点配置文件</span>]: </span><br><span class="line"><span class="link">\_config.yml</span></span><br><span class="line">[<span class="symbol">主题配置文件</span>]: </span><br><span class="line"><span class="link">\themes\pure\_config.yml"关于、个人介绍、公告"</span></span><br><span class="line">[<span class="symbol">友链文件</span>]: </span><br><span class="line"><span class="link">\source\_data\links.yml</span></span><br><span class="line">[<span class="symbol">语言</span>]: </span><br><span class="line"><span class="link">\themes\pure\languages</span></span><br><span class="line">[<span class="symbol">左下角运行时间</span>]: </span><br><span class="line"><span class="link">\themes\pure\layout\_common\footer.ejs"时间、版权"</span></span><br><span class="line">[<span class="symbol">评论角色配置</span>]: </span><br><span class="line"><span class="link">\themes\pure\layout\_script\_comment\valine.ejs</span></span><br><span class="line">[<span class="symbol">css样式</span>]:</span><br><span class="line"><span class="link">\themes\pure\source\css\style.css</span></span><br><span class="line">[<span class="symbol">搜索栏限制</span>]: </span><br><span class="line"><span class="link">\themes\pure\source\js\insight.js"160行"</span></span><br></pre></td></tr></table></figure><hr><h2 id="六-内容样例">六. 内容样例<a class="header-anchor" href="#六-内容样例"></a></h2><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">---</span><br><span class="line">title: Test</span><br><span class="line">date: 2022-08-28 00:09:00</span><br><span class="line">updated: 2022-08-28 00:09:01</span><br><span class="line">thumbnail: https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-fiasdjucgf/image/test.png</span><br><span class="line">tags:</span><br><span class="line"><span class="bullet"> -</span> Test</span><br><span class="line">category:</span><br><span class="line"><span class="bullet"> -</span> Test</span><br><span class="line">toc: true</span><br><span class="line"><span class="section">top: true</span></span><br><span class="line"><span class="section">---</span></span><br><span class="line">描述<!-- more --></span><br></pre></td></tr></table></figure><h3 id="文章指定多个-category">文章指定多个 category<a class="header-anchor" href="#文章指定多个-category"></a></h3><blockquote><p>多个分类</p><p>如果我们的要求是将文章同时分到两个或者多个不同的类目下呢?官方给出的方法是:</p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">categories:</span><br><span class="line"> - [Sports]</span><br><span class="line"> - [Baseball]</span><br></pre></td></tr></table></figure><p>参考文章:<a href="https://www.jianshu.com/p/4438c417611e">Hexo 一篇文章多个 categories https://www.jianshu.com/p/4438c417611e</a></p></blockquote><hr><h2 id="七-自定义">七. 自定义<a class="header-anchor" href="#七-自定义"></a></h2><h3 id="7-1-搜索框索引突破-5">7.1 搜索框索引突破 5<a class="header-anchor" href="#7-1-搜索框索引突破-5"></a></h3><ol><li class="lvl-3"><p><code>F12</code> 定位到搜索框的 类选择器 为 ins-section-header</p></li><li class="lvl-3"><p>grep,定位到配置文件为 <code>\themes\pure\source\js\insight.js</code></p></li><li class="lvl-3"><p>Ctrl + F,搜索 5,定位到第 160 行,修改限制</p></li></ol><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830075511578.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830075224471.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830075722865.png" alt=""></p></blockquote><h3 id="7-2-左侧头像链接,target-修改为-self">7.2 左侧头像链接,target 修改为 _self<a class="header-anchor" href="#7-2-左侧头像链接,target-修改为-self"></a></h3><p>a 标签,修改 target: ‘_blank’ → ‘_self’</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830080811356.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830080916410.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220830080945424.png" alt=""></p></blockquote><hr><h3 id="7-3-文章目录,一级标题不跳转">7.3 文章目录,一级标题不跳转<a class="header-anchor" href="#7-3-文章目录,一级标题不跳转"></a></h3><p>有时发现一级标题不会跳转</p><p><s>配置文件<code>\node_modules\hexo\lib\plugins\helper\toc.js</code></s></p><p><s>更新下 <code>\node_modules\hexo\lib\plugins\helper\toc.js</code> 文件,又正常了。时灵时不灵的。。。</s></p><p><s>参考<a href="https://hwame.top/20200520/hello-hexo-troubleshooting.html#3-%E5%A6%82%E4%BD%95%E5%8F%96%E6%B6%88%E6%96%87%E7%AB%A0%E7%9B%AE%E5%BD%95%E7%9A%84%E8%87%AA%E5%8A%A8%E7%BC%96%E5%8F%B7">https://hwame.top/如何取消文章目录的自动编号</a></s></p><p>修改 “.\node_modules\hexo-renderer-markdown-it\index.js” level 为 1</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220906033013691.png" alt=""></p></blockquote><ul class="lvl-0"><li class="lvl-2"><p>参考文章:</p><p><a href="https://blog.csdn.net/Fosu_Chenai/article/details/111192850">https://blog.csdn.net/Fosu_Chenai/article/details/111192850 评论</a></p></li></ul><hr><h3 id="7-4-滚动条加粗-加小箭头">7.4 滚动条加粗 + 加小箭头<a class="header-anchor" href="#7-4-滚动条加粗-加小箭头"></a></h3><ul class="lvl-0"><li class="lvl-2"><p>修改 css 样式,路径 <code>.\hexo-source\themes\pure\source\css\style.css</code></p><ol><li class="lvl-5"><code>Ctlrl + F</code> 定位 <code>scrollbar</code>;</li><li class="lvl-5">调高 <code>height</code>,使代码框 右拉滚动条加粗;</li><li class="lvl-5">右侧下拉条变粗;</li></ol><blockquote><p><strong>7.4.1 代码框加粗</strong></p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * scrollbar</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">15px</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">14px</span>;# 调高</span><br><span class="line"> <span class="attribute">background</span>: transparent;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901164700329.png" alt=""></p><p><strong>7.4.2 右侧下拉条变粗 + 添加小箭头</strong></p><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * 滚动条箭头</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">::-webkit-scrollbar-button {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">0px</span>;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">4px</span>;</span><br><span class="line"> <span class="attribute">display</span>: block; </span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#c3c3c3</span>;</span><br><span class="line">}</span><br><span class="line">::-webkit-scrollbar {</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">16px</span>;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">5px</span> solid white;</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-thumb {</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#b0b0b0</span>;</span><br><span class="line"> <span class="attribute">background-clip</span>: padding-box;</span><br><span class="line"> <span class="attribute">border</span>: <span class="number">0.05em</span> solid <span class="number">#eeeeee</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-track {</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#bbbbbb</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">/* Buttons */</span></span><br><span class="line">::-webkit-scrollbar-button:single-button {</span><br><span class="line"> <span class="attribute">background-color</span>: <span class="number">#bbbbbb</span>;</span><br><span class="line"> <span class="attribute">display</span>: block;</span><br><span class="line"> <span class="attribute">border-style</span>: solid;</span><br><span class="line"> <span class="attribute">height</span>: <span class="number">13px</span>;</span><br><span class="line"> <span class="attribute">width</span>: <span class="number">16px</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">/* Up */</span></span><br><span class="line">::-webkit-scrollbar-button:single-button:vertical:decrement {</span><br><span class="line"> <span class="attribute">border-width</span>: <span class="number">0px</span> <span class="number">8px</span> <span class="number">8px</span> <span class="number">8px</span>;</span><br><span class="line"> <span class="attribute">border-color</span>: transparent transparent <span class="number">#555555</span> transparent;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-button:single-button:vertical:decrement:hover {</span><br><span class="line"> <span class="attribute">border-color</span>: transparent transparent <span class="number">#777777</span> transparent;</span><br><span class="line">}</span><br><span class="line"><span class="comment">/* Down */</span></span><br><span class="line">::-webkit-scrollbar-button:single-button:vertical:increment {</span><br><span class="line"> <span class="attribute">border-width</span>: <span class="number">8px</span> <span class="number">8px</span> <span class="number">0</span> <span class="number">8px</span>;</span><br><span class="line"> <span class="attribute">border-color</span>: <span class="number">#555555</span> transparent transparent transparent;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-button:vertical:single-button:increment:hover {</span><br><span class="line"> <span class="attribute">border-color</span>: <span class="number">#777777</span> transparent transparent transparent;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901164914382.png" alt=""></p></blockquote></li></ul><p><strong>参考文章</strong></p><ul class="lvl-0"><li class="lvl-2"><p><a href="http://www.qianduanheidong.com/blog/article/27901/a1c9346c7830d6ffa3f2/">右侧下拉条新增箭头</a></p></li><li class="lvl-2"><p><a href="https://www.php.cn/css-tutorial-475268.html">:-webkit-scrollbar 滚动条整体部分 https://www.php.cn/css-tutorial-475268.html</a></p></li></ul><h3 id="7-5-Valine-评论框添加一言">7.5 Valine 评论框添加一言<a class="header-anchor" href="#7-5-Valine-评论框添加一言"></a></h3><p><strong>参考文章</strong></p><ul class="lvl-0"><li class="lvl-2"><p><a href="https://blog.justlovesmile.top/posts/27831.html">https://blog.justlovesmile.top/posts/27831.html</a></p></li></ul><p>偶然看到的文章,然后自己就加了这个功能。</p><ul class="lvl-0"><li class="lvl-2"><p>路径:<code>.\themes\pure\layout\_script\_comment\valine.ejs</code>;</p></li><li class="lvl-2"><p>加到最后 <code></script></code> 标签之前;c=j 请求获得网易云的句子,开始网抑云吧;</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">fetch('https://v1.hitokoto.cn/?c=j')</span><br><span class="line">.then(response => response.json())</span><br><span class="line">.then(data => {</span><br><span class="line"> document.getElementById("veditor").setAttribute("placeholder",data.hitokoto+"__"+data.from);</span><br><span class="line">})</span><br><span class="line">.catch(console.error)</span><br></pre></td></tr></table></figure></li></ul><blockquote><p>修改方法:</p><ol><li class="lvl-3"><p>找到博客对应添加valine的位置,例如Ayer主题的位于hexo\themes\ayer\layout_partial\post\valine.ejs</p></li><li class="lvl-3"><p>在内部添加一段代码:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><script type="text/javascript"></span><br><span class="line"> fetch('https://v1.hitokoto.cn')</span><br><span class="line"> .then(response => response.json())</span><br><span class="line"> .then(data => {</span><br><span class="line"> document.getElementById("veditor").setAttribute("placeholder",data.hitokoto+"__"+data.from);</span><br><span class="line"> })</span><br><span class="line"> .catch(console.error)</span><br><span class="line"></script></span><br></pre></td></tr></table></figure></li><li class="lvl-3"><p>Api接口说明:<br>(1)<a href="https://v1.hitokoto.cn/">https://v1.hitokoto.cn/</a> (从7种分类中随机抽取)<br>(2)<a href="https://v1.hitokoto.cn/?c=b">https://v1.hitokoto.cn/?c=b</a> (请求获得一个分类是漫画的句子)<br>参数说明<br>a动画<br>b漫画<br>c游戏<br>d文学<br>e原创<br>f来自网络<br>g其他<br>h影视<br>i诗词<br>j网易云<br>k哲学<br>l抖机灵<br>其他作为动画类型处理<br>可选择多个分类,例如: ?c=a&c=c</p></li></ol><p>(3)<a href="https://v1.hitokoto.cn/?c=f&encode=text">https://v1.hitokoto.cn/?c=f&encode=text</a> (请求获得一个来自网络的句子,并以纯文本格式输出)</p><ol start="4"><li class="lvl-3"><p>返回的格式说明<br>返回参数名称描述<br>id一言标识<br>hitokoto一言正文。编码方式 unicode。使用 utf-8。<br>type类型<br>from一言的出处<br>from_who一言的作者<br>creator添加者<br>creator_uid添加者用户标识<br>reviewer审核员标识<br>uuid一言唯一标识;可以链接到 <a href="https://hitokoto.cn?uuid=%5Buuid%5D">https://hitokoto.cn?uuid=[uuid]</a> 查看这个一言的完整信息<br>commit_from提交方式<br>created_at添加时间<br>length句子长度<br>例如:返回的data,通过data.hitokoto获取句子正文</p></li></ol><p>作者: Justlovesmile<br>链接: <a href="https://blog.justlovesmile.top/posts/27831.html">https://blog.justlovesmile.top/posts/27831.html</a><br>来源: Justlovesmile’s BLOG<br>著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。</p></blockquote><p>PS:这位大佬的博客真好看~~</p><h3 id="7-6-左侧-归档、分类-改为默认收起">7.6 左侧 归档、分类 改为默认收起<a class="header-anchor" href="#7-6-左侧-归档、分类-改为默认收起"></a></h3><ul class="lvl-0"><li class="lvl-2"><p>默认是展开的</p></li></ul><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203849607.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203907981.png" alt=""></p></blockquote><ul class="lvl-0"><li class="lvl-2"><p>修改以下文件,改为收起状态。如图</p><ul class="lvl-2"><li class="lvl-4">style=“height: 0px” 应该可以不用写,收起状态默认就是 0 ~~</li></ul></li></ul><blockquote><p><code>.\themes\pure\layout\categories.ejs</code></p><p><code>.\themes\pure\layout\_partial\archive.ejs</code></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203746673.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901203807739.png" alt=""></p></blockquote><hr><h2 id="八-未解决的小需求">八. 未解决的小需求<a class="header-anchor" href="#八-未解决的小需求"></a></h2><ol><li class="lvl-3"><p>(已解决,#7.3)一级目录,右侧导航栏 有时跳转失败;</p></li><li class="lvl-3"><p>Valine 评论系统,下面的评论 被@后,未显示 @信息,而别人的是成功的;</p><blockquote><p>我的</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901171817579.png" alt=""></p><p>其他大佬的</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901171912131.png" alt=""></p></blockquote></li><li class="lvl-3"><p>引用时 使用 #,会被导航目录误认为 一级标题;</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901172133945.png" alt=""></p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901172316157.png" alt=""></p></blockquote></li><li class="lvl-3"><p>(已解决)生成在 /public 目录的静态文件都被压缩了,<s>我看别人的没被压缩,不清楚啥原因。</s> 因为配置了这个 <a href="https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md#%E5%8D%9A%E5%AE%A2%E4%BC%98%E5%8C%96">https://github.com/cofess/hexo-theme-pure/blob/master/README.cn.md 博客优化</a> 压缩了文件</p><blockquote><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220901175404486.png" alt=""></p></blockquote></li><li class="lvl-3"><p>(已解决)文章内部一级、二级…标题左侧无锚点</p><blockquote><p>理想效果图</p><p><img src="https://cdn.jsdmirror.com/npm/mycpen-image-bed@0.0.0-2022/image/20220906034109271.png" alt=""></p><p><s>似乎是环境配置问题,我用虚拟机推送静态文件,就有显示;用真实 win机 推送 就没有锚点,重装 git 也没显示(可能不是 git 的问题)。。。</s></p><p>因为压缩了静态文件,全部注释 <code>hexo-neat</code> 配置。<br>参考<br><a href="https://github.com/cofess/hexo-theme-pure#hexo-neat">https://github.com/cofess/hexo-theme-pure#hexo-neat</a><br><a href="https://github.com/rozbo/hexo-neat#options">https://github.com/rozbo/hexo-neat#options</a></p></blockquote></li></ol><p>无伤大雅,<s>我一般一级标题写的是文章标题</s>;评论区也就是个摆设;<s>静态文件被压缩,可能别人还觉得我是故意,嘿</s>~~</p><p>最后总结:魔改要适量,太费时 还得不到提升,不如多看几个前端视频 多写几篇文章。。。</p><hr>]]></content>
|
1522
1522
|
|
1523
1523
|
|
1524
1524
|
<categories>
|