快轉到主要內容

Hugo 的文章結構

·846 字·2 分鐘
目錄

Organization
#

content/ 下的檔案結構會反映在你的weblink上:
first_post.md的url會是https://example.org/posts/firstpost/first_post
subpost.md 的url是https://example.org/posts/firstpost/sub_post/subpost

content/
├─ posts/
│  ├─ first_post.md
│  ├─ second_post.md
│  ├─ sub_post/
│  │  ├─ subpost.md
├─ travel/
│  ├─ summer.md
│  ├─ spring.md
_index.md

Page Boundle
#

Page bundle是一個folder下面有文章和相關的resources(e.g.圖檔),分成兩種:

  • Leafe boundle - folder下面必有一個 index.md,resource檔可有可無,該foder下面不會有其他的子目錄
  • Branch bundle - folder下面必有 _index.md,resource檔也是可有可無,他會包含其他descendants。

_index.md
#

他是一個目錄路徑,你可以在裡面設定front matter。如果該目錄沒有_index.md,你就無法在網頁上看到這個目錄。以上圖(樹狀圖)為例,posts下面沒有_index.md,https://example.org/posts/ 就會無法顯示,但你依然可以直接指定訪問你的md檔。 設定該檔案的好處是你可以直接使用該folder下的resource (e.g. image)。另外,包和_index.md的folder我們稱為一個section。

Section
#

top level folder,也就是content/, 它本身就是一個section;另外只要有_index.md的folder都是section。section會有list page,在網頁上就會看到該section下的folders。如下圖,content/posts/是一個 section,

content/
├─ posts/
│  ├─ first_post.md
│  ├─ second_post.md
│  ├─ sub_post/
│  │  ├─ subpost.md
│  │  ├─ index.md
│  ├─ _index.md
├─ travel/
│  ├─ summer.md
│  ├─ spring.md
_index.md

https://example.org/posts/ 下面你會看到:

first_post.md  
second_post.md  
sub_post(1)

若你將架構改成下圖:

content/
├─ posts/
│  ├─ first_post/
│  │  ├─ first.md
│  │  ├─ first2.md
│  │  ├─ _index.md
│  ├─ _index.md
│  ├─ second_post/
│  │  ├─ second.md
│  │  ├─ _index.md/
├─ travel/
│  ├─ summer.md
│  ├─ spring.md
_index.md

https://example.org/posts/ 下面你會看到:

first_post(2) 
second_post(1)

相關文章
#

🔗 Hugo section
🔗 Content organization
🔗 ASCII Tree Generator