xianmin / hugo-theme-jane

A readable & concise theme for Hugo
https://xianmin.github.io/hugo-theme-jane/
MIT License
921 stars 284 forks source link

[solved]how to add URL prefix to default language? #334

Closed CyrusYip closed 2 years ago

CyrusYip commented 2 years ago

I am trying to build a bilingual site. English is default language, another language is Simplified Chinese. The URL of Chinese site is prefixed with zh-ch.

http://localhost:1313/zh-cn/
http://localhost:1313/zh-cn/post/

However, the URL of default language(English) site is not prefixed with en.

http://localhost:1313/
http://localhost:1313/post/

How can I make the URL of the default site prefixed with its language code(en)? I want to make it look like this:

http://localhost:1313/en/
http://localhost:1313/en/post/
CyrusYip commented 2 years ago

I solved this issue by putting defaultContentLanguageInSubdir = "true" above [permalinks]. If it does not work, you can put it at top of config.toml.

 googleAnalytics = ""      # UA-XXXXXXXX-X
 copyright = ""            # default: author.name ↓        # 默认为下面配置的author.name ↓

+defaultContentLanguageInSubdir = "true" # Render English site under /en
 [permalinks]
   post = "/post/:year/:month/:day/:slug/"
 # language support # en / zh-cn / other... translations present in i18n/
original config.toml ``` # This is a simple configuration. # If you want to see the full configuration, please check `full-config.toml` . # And see https://gohugo.io/getting-started/configuration/ . baseURL = "http://localhost:1313/" title = "Jane - A super concise theme for Hugo" enableRobotsTXT = true enableEmoji = true theme = "jane" hasCJKLanguage = true # has chinese/japanese/korean ? # 自动检测是否包含 中文\日文\韩文 paginate = 3 # Number of articles displayed on the homepage # 首页每页显示的文章数 rssLimit = 20 # Limit Entry Count to Rss file # 限制 Rss 文章输出数量 disqusShortname = "" # disqus_shortname googleAnalytics = "" # UA-XXXXXXXX-X copyright = "" # default: author.name ↓ # 默认为下面配置的author.name ↓ [permalinks] post = "/post/:year/:month/:day/:slug/" # language support # en / zh-cn / other... translations present in i18n/ defaultContentLanguage = "en" # Default language to use [langusges] [languages.en] title = "english site" languageName = "English" # languageCode = "en" # weight = 2 [languages.zh-cn] title = "中文网站" languageName = "简体中文" # languageCode = "zh-cn" # weight = 1 [author] # essential # 必需 name = "xianmin" [sitemap] # essential # 必需 changefreq = "weekly" priority = 0.5 filename = "sitemap.xml" [[languages.en.menu.main]] name = "Home" weight = 10 identifier = "home" url = "/" [[languages.en.menu.main]] name = "Archives" weight = 20 identifier = "archives" url = "/post/" [[languages.en.menu.main]] name = "Tags" weight = 30 identifier = "tags" url = "/tags/" [[languages.en.menu.main]] name = "Categories" weight = 40 identifier = "categories" url = "/categories/" [[languages.zh-cn.menu.main]] name = "主页" weight = 10 identifier = "home" url = "zh-cn/" [[languages.zh-cn.menu.main]] name = "归档" weight = 20 identifier = "archives" url = "zh-cn/post/" [[languages.zh-cn.menu.main]] name = "标签" weight = 30 identifier = "tags" url = "zh-cn/tags/" [[languages.zh-cn.menu.main]] name = "分类" weight = 40 identifier = "categories" url = "zh-cn/categories/" [params] since = "2017" # Site creation time # 站点建立时间 homeFullContent = false # if false, show post summaries on home page. Otherwise show full content. rssFullContent = true # if false, Rss feed instead of the summary # site info (optional) # 站点信息(可选,不需要的可以直接注释掉) logoTitle = "Jane" # default: the title value # 默认值: 上面设置的title值 keywords = ["Hugo", "theme","jane"] description = "Hugo theme jane example site." # The date format to use; for a list of valid formats, see https://gohugo.io/functions/format/ dateFormatToUse = "2006-01-02" # 一些全局开关,你也可以在每一篇内容的 front matter 中针对单篇内容关闭或开启某些功能,在 archetypes/default.md 查看更多信息。 # Some global options, you can also close or open something in front matter for a single post, see more information from `archetypes/default.md`. toc = true # 是否开启目录 photoswipe = true # see https://github.com/dimsemenov/PhotoSwipe # 是否启用PhotoSwipe(图片可点击) contentCopyright = 'CC BY-NC-ND 4.0' # Link custom CSS and JS assets # (relative to /static/css and /static/js respectively) customCSS = [] # if ['custom.css'], load '/static/css/custom.css' file customJS = [] # if ['custom.js'], load '/static/js/custom.js' file # language chooser showMenuLanguageChooser = true [params.social] # 社交链接 a-email = "mailto:your@email.com" b-stack-overflow = "http://localhost:1313" c-twitter = "http://localhost:1313" d-facebook = "http://localhost:1313" e-linkedin = "http://localhost:1313" f-google = "http://localhost:1313" g-github = "http://localhost:1313" h-weibo = "http://localhost:1313" i-zhihu = "http://localhost:1313" j-douban = "http://localhost:1313" k-pocket = "http://localhost:1313" l-tumblr = "http://localhost:1313" m-instagram = "http://localhost:1313" n-gitlab = "http://localhost:1313" o-goodreads = "http://localhost:1313" p-coding = "http://localhost:1313" q-bilibili = "http://localhost:1313" r-codeforces = "http://localhost:1313" s-mastodon = "http://localhost:1313" t-youtube = "http://localhost:1313" u-twitch = "http://localhost:1313" ```
fixed config.toml ``` # This is a simple configuration. # If you want to see the full configuration, please check `full-config.toml` . # And see https://gohugo.io/getting-started/configuration/ . baseURL = "http://localhost:1313/" title = "Jane - A super concise theme for Hugo" enableRobotsTXT = true enableEmoji = true theme = "jane" hasCJKLanguage = true # has chinese/japanese/korean ? # 自动检测是否包含 中文\日文\韩文 paginate = 3 # Number of articles displayed on the homepage # 首页每页显示的文章数 rssLimit = 20 # Limit Entry Count to Rss file # 限制 Rss 文章输出数量 disqusShortname = "" # disqus_shortname googleAnalytics = "" # UA-XXXXXXXX-X copyright = "" # default: author.name ↓ # 默认为下面配置的author.name ↓ defaultContentLanguageInSubdir = "true" # Render English site under /en [permalinks] post = "/post/:year/:month/:day/:slug/" # language support # en / zh-cn / other... translations present in i18n/ defaultContentLanguage = "en" # Default language to use [langusges] [languages.en] title = "english site" languageName = "English" # languageCode = "en" # weight = 2 [languages.zh-cn] title = "中文网站" languageName = "简体中文" # languageCode = "zh-cn" # weight = 1 [author] # essential # 必需 name = "xianmin" [sitemap] # essential # 必需 changefreq = "weekly" priority = 0.5 filename = "sitemap.xml" [[languages.en.menu.main]] name = "Home" weight = 10 identifier = "home" url = "/" [[languages.en.menu.main]] name = "Archives" weight = 20 identifier = "archives" url = "/post/" [[languages.en.menu.main]] name = "Tags" weight = 30 identifier = "tags" url = "/tags/" [[languages.en.menu.main]] name = "Categories" weight = 40 identifier = "categories" url = "/categories/" [[languages.zh-cn.menu.main]] name = "主页" weight = 10 identifier = "home" url = "zh-cn/" [[languages.zh-cn.menu.main]] name = "归档" weight = 20 identifier = "archives" url = "zh-cn/post/" [[languages.zh-cn.menu.main]] name = "标签" weight = 30 identifier = "tags" url = "zh-cn/tags/" [[languages.zh-cn.menu.main]] name = "分类" weight = 40 identifier = "categories" url = "zh-cn/categories/" [params] since = "2017" # Site creation time # 站点建立时间 homeFullContent = false # if false, show post summaries on home page. Otherwise show full content. rssFullContent = true # if false, Rss feed instead of the summary # site info (optional) # 站点信息(可选,不需要的可以直接注释掉) logoTitle = "Jane" # default: the title value # 默认值: 上面设置的title值 keywords = ["Hugo", "theme","jane"] description = "Hugo theme jane example site." # The date format to use; for a list of valid formats, see https://gohugo.io/functions/format/ dateFormatToUse = "2006-01-02" # 一些全局开关,你也可以在每一篇内容的 front matter 中针对单篇内容关闭或开启某些功能,在 archetypes/default.md 查看更多信息。 # Some global options, you can also close or open something in front matter for a single post, see more information from `archetypes/default.md`. toc = true # 是否开启目录 photoswipe = true # see https://github.com/dimsemenov/PhotoSwipe # 是否启用PhotoSwipe(图片可点击) contentCopyright = 'CC BY-NC-ND 4.0' # Link custom CSS and JS assets # (relative to /static/css and /static/js respectively) customCSS = [] # if ['custom.css'], load '/static/css/custom.css' file customJS = [] # if ['custom.js'], load '/static/js/custom.js' file # language chooser showMenuLanguageChooser = true [params.social] # 社交链接 a-email = "mailto:your@email.com" b-stack-overflow = "http://localhost:1313" c-twitter = "http://localhost:1313" d-facebook = "http://localhost:1313" e-linkedin = "http://localhost:1313" f-google = "http://localhost:1313" g-github = "http://localhost:1313" h-weibo = "http://localhost:1313" i-zhihu = "http://localhost:1313" j-douban = "http://localhost:1313" k-pocket = "http://localhost:1313" l-tumblr = "http://localhost:1313" m-instagram = "http://localhost:1313" n-gitlab = "http://localhost:1313" o-goodreads = "http://localhost:1313" p-coding = "http://localhost:1313" q-bilibili = "http://localhost:1313" r-codeforces = "http://localhost:1313" s-mastodon = "http://localhost:1313" t-youtube = "http://localhost:1313" u-twitch = "http://localhost:1313" ```