<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>BaseUrl on Logan的博客</title>
        <link>https://qh.1357810.xyz/tags/baseurl/</link>
        <description>Recent content in BaseUrl on Logan的博客</description>
        <generator>Hugo -- gohugo.io</generator>
        <language>zh-cn</language>
        <copyright>logan</copyright>
        <lastBuildDate>Wed, 10 Apr 2024 00:00:00 +0800</lastBuildDate><atom:link href="https://qh.1357810.xyz/tags/baseurl/index.xml" rel="self" type="application/rss+xml" /><item>
        <title>hugo博客-配置baseUrl的坑</title>
        <link>https://qh.1357810.xyz/articles/with-hugo/hugo-baseurl/</link>
        <pubDate>Wed, 10 Apr 2024 00:00:00 +0800</pubDate>
        
        <guid>https://qh.1357810.xyz/articles/with-hugo/hugo-baseurl/</guid>
        <description>&lt;img src="https://logan.1357810.xyz/cover/pic_075.jpg" alt="Featured image of post hugo博客-配置baseUrl的坑" /&gt;&lt;h1 id=&#34;hugo博客-配置baseurl的坑&#34;&gt;
    &lt;a href=&#34;#hugo%e5%8d%9a%e5%ae%a2-%e9%85%8d%e7%bd%aebaseurl%e7%9a%84%e5%9d%91&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;  
    hugo博客 配置baseUrl的坑
&lt;/h1&gt;&lt;h2 id=&#34;本地启动&#34;&gt;
    &lt;a href=&#34;#%e6%9c%ac%e5%9c%b0%e5%90%af%e5%8a%a8&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;  
    本地启动
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;不管配置文件怎么改，默认的&lt;code&gt;baseUrl&lt;/code&gt;都为&lt;code&gt;localhost&lt;/code&gt;，bind的ip为&lt;code&gt;127.0.0.1&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;生成的public里的html中的url都不会是你配置文件里的&lt;code&gt;baseUrl&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;-D包含草稿&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;logan-code-block&#34;&gt;
    &lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34; id=&#34;hl-0-1&#34;&gt;&lt;a class=&#34;lnlinks&#34; href=&#34;#hl-0-1&#34;&gt;1&lt;/a&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;hugo server -D&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;

  &lt;div class=&#34;code-scroll&#34; aria-label=&#34;代码块滚动工具栏&#34;&gt;
    &lt;button class=&#34;code-scroll-left iconfont-logan icon-logan-circle-left-solid&#34; aria-label=&#34;向左滚动&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;code-scroll-right iconfont-logan icon-logan-circle-right-solid&#34; aria-label=&#34;向右滚动&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;

  &lt;div class=&#34;code-tools&#34; aria-label=&#34;代码块工具栏&#34;&gt;
    &lt;div class=&#34;copy-text&#34;&gt;Copied!&lt;/div&gt;
    &lt;button class=&#34;copy-code-button iconfont-logan icon-logan-copy-round3&#34; aria-label=&#34;复制&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;my-code-fold iconfont-logan icon-logan-circle-chevron-down-solid expand1&#34; aria-label=&#34;折叠&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;除非在后面加上-baseurl&#34;&gt;
    &lt;a href=&#34;#%e9%99%a4%e9%9d%9e%e5%9c%a8%e5%90%8e%e9%9d%a2%e5%8a%a0%e4%b8%8a-baseurl&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;  
    除非在后面加上 &amp;ndash;baseURL
&lt;/h2&gt;
&lt;div class=&#34;logan-code-block&#34;&gt;
    &lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34; id=&#34;hl-1-1&#34;&gt;&lt;a class=&#34;lnlinks&#34; href=&#34;#hl-1-1&#34;&gt;1&lt;/a&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;hugo server -D --baseURL http://www.xxx.com/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;

  &lt;div class=&#34;code-scroll&#34; aria-label=&#34;代码块滚动工具栏&#34;&gt;
    &lt;button class=&#34;code-scroll-left iconfont-logan icon-logan-circle-left-solid&#34; aria-label=&#34;向左滚动&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;code-scroll-right iconfont-logan icon-logan-circle-right-solid&#34; aria-label=&#34;向右滚动&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;

  &lt;div class=&#34;code-tools&#34; aria-label=&#34;代码块工具栏&#34;&gt;
    &lt;div class=&#34;copy-text&#34;&gt;Copied!&lt;/div&gt;
    &lt;button class=&#34;copy-code-button iconfont-logan icon-logan-copy-round3&#34; aria-label=&#34;复制&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;my-code-fold iconfont-logan icon-logan-circle-chevron-down-solid expand1&#34; aria-label=&#34;折叠&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;启动局域网连接&#34;&gt;
    &lt;a href=&#34;#%e5%90%af%e5%8a%a8%e5%b1%80%e5%9f%9f%e7%bd%91%e8%bf%9e%e6%8e%a5&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;  
    启动局域网连接
&lt;/h2&gt;
&lt;div class=&#34;logan-code-block&#34;&gt;
    &lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34; id=&#34;hl-2-1&#34;&gt;&lt;a class=&#34;lnlinks&#34; href=&#34;#hl-2-1&#34;&gt;1&lt;/a&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;hugo server -D --bind&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;0.0.0.0 --port&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1313&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;

  &lt;div class=&#34;code-scroll&#34; aria-label=&#34;代码块滚动工具栏&#34;&gt;
    &lt;button class=&#34;code-scroll-left iconfont-logan icon-logan-circle-left-solid&#34; aria-label=&#34;向左滚动&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;code-scroll-right iconfont-logan icon-logan-circle-right-solid&#34; aria-label=&#34;向右滚动&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;

  &lt;div class=&#34;code-tools&#34; aria-label=&#34;代码块工具栏&#34;&gt;
    &lt;div class=&#34;copy-text&#34;&gt;Copied!&lt;/div&gt;
    &lt;button class=&#34;copy-code-button iconfont-logan icon-logan-copy-round3&#34; aria-label=&#34;复制&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;my-code-fold iconfont-logan icon-logan-circle-chevron-down-solid expand1&#34; aria-label=&#34;折叠&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;所以本地开发测试时，不需要关心&lt;code&gt;baseUrl&lt;/code&gt;，server启动时就一定是&lt;code&gt;localhost&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;本地或服务器打包&#34;&gt;
    &lt;a href=&#34;#%e6%9c%ac%e5%9c%b0%e6%88%96%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%89%93%e5%8c%85&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;  
    本地或服务器打包
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;打包时，hugo会严格按照配置文件中的&lt;code&gt;baseUrl&lt;/code&gt;创建静态页面，与&lt;code&gt;--environment&lt;/code&gt;无关&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--gc&lt;/code&gt;构建站点时会自动执行垃圾回收;&lt;code&gt;--minify&lt;/code&gt;对输出的 HTML、CSS 和 JavaScript 进行压缩和优化&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;logan-code-block&#34;&gt;
    &lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34; id=&#34;hl-3-1&#34;&gt;&lt;a class=&#34;lnlinks&#34; href=&#34;#hl-3-1&#34;&gt;1&lt;/a&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;hugo -D --gc --minify&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;

  &lt;div class=&#34;code-scroll&#34; aria-label=&#34;代码块滚动工具栏&#34;&gt;
    &lt;button class=&#34;code-scroll-left iconfont-logan icon-logan-circle-left-solid&#34; aria-label=&#34;向左滚动&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;code-scroll-right iconfont-logan icon-logan-circle-right-solid&#34; aria-label=&#34;向右滚动&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;

  &lt;div class=&#34;code-tools&#34; aria-label=&#34;代码块工具栏&#34;&gt;
    &lt;div class=&#34;copy-text&#34;&gt;Copied!&lt;/div&gt;
    &lt;button class=&#34;copy-code-button iconfont-logan icon-logan-copy-round3&#34; aria-label=&#34;复制&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;my-code-fold iconfont-logan icon-logan-circle-chevron-down-solid expand1&#34; aria-label=&#34;折叠&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;服务器多环境打包&#34;&gt;
    &lt;a href=&#34;#%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%a4%9a%e7%8e%af%e5%a2%83%e6%89%93%e5%8c%85&#34; class=&#34;header-anchor&#34;&gt;&lt;/a&gt;  
    服务器多环境打包
&lt;/h2&gt;&lt;p&gt;我的博客，同一套代码在&lt;code&gt;github pages&lt;/code&gt;和&lt;code&gt;vercel&lt;/code&gt;上都有部署,分别是不同的域名，所以就需要区分两个环境的&lt;code&gt;baseUrl&lt;/code&gt;,我是这样做的：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;把原本的&lt;code&gt;hugo.yaml&lt;/code&gt;当作是&lt;code&gt;vercel&lt;/code&gt; 的配置，复制原本的配置为&lt;code&gt;hugo-git.yaml&lt;/code&gt;当作&lt;code&gt;github pages&lt;/code&gt;的配置&lt;/li&gt;
&lt;li&gt;两个文件只有&lt;code&gt;baseUrl&lt;/code&gt;不同&lt;/li&gt;
&lt;li&gt;在启动Hugo打包的时候，需要加具体的配置文件名参数&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;logan-code-block&#34;&gt;
    &lt;div class=&#34;highlight&#34;&gt;&lt;div class=&#34;chroma&#34;&gt;
&lt;table class=&#34;lntable&#34;&gt;&lt;tr&gt;&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code&gt;&lt;span class=&#34;lnt&#34; id=&#34;hl-4-1&#34;&gt;&lt;a class=&#34;lnlinks&#34; href=&#34;#hl-4-1&#34;&gt;1&lt;/a&gt;
&lt;/span&gt;&lt;span class=&#34;lnt&#34; id=&#34;hl-4-2&#34;&gt;&lt;a class=&#34;lnlinks&#34; href=&#34;#hl-4-2&#34;&gt;2&lt;/a&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;td class=&#34;lntd&#34;&gt;
&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;hugo -D --gc --minify --config hugo.yaml &lt;span class=&#34;c1&#34;&gt;# 在vercel上使用，默认为vercel&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;hugo -D --gc --minify --config hugo-git.yaml &lt;span class=&#34;c1&#34;&gt;#在github action中使用&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;

  &lt;div class=&#34;code-scroll&#34; aria-label=&#34;代码块滚动工具栏&#34;&gt;
    &lt;button class=&#34;code-scroll-left iconfont-logan icon-logan-circle-left-solid&#34; aria-label=&#34;向左滚动&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;code-scroll-right iconfont-logan icon-logan-circle-right-solid&#34; aria-label=&#34;向右滚动&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;

  &lt;div class=&#34;code-tools&#34; aria-label=&#34;代码块工具栏&#34;&gt;
    &lt;div class=&#34;copy-text&#34;&gt;Copied!&lt;/div&gt;
    &lt;button class=&#34;copy-code-button iconfont-logan icon-logan-copy-round3&#34; aria-label=&#34;复制&#34;&gt;&lt;/button&gt;
    &lt;button class=&#34;my-code-fold iconfont-logan icon-logan-circle-chevron-down-solid expand1&#34; aria-label=&#34;折叠&#34;&gt;&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;
</description>
        </item>
        
    </channel>
</rss>
