轉載自:http://orzcss.com/posts/5a207d64/
概述
默認安裝的 hexo 本身是沒有分類和標簽首頁的,
例如:http://orzcss.com/categories/
頁面打開后,總是顯示 Cannot GET /categories/
嘗試了很多方法還是無效。
找了很多資料,都沒有人提供解決方案,更多的是沒有答案的問題,也許是這個問題太簡單了,沒人願意記錄筆記。
現在告訴大家怎么實現。
步驟一
新建一個頁面,命名為 ‘categories’ | ‘tags’。命令如下:
1 2 3
|
hexo new page "categories"
hexo new page "tags"
|
步驟二
編輯剛新建的頁面,將頁面的類型設置為 categories | tags ,主題將自動為這個頁面顯示 分類|標簽雲。頁面內容如下:
1 2 3 4 5
|
--- title: 分類 date: 2016-10-21 11:59:10 type: "categories" ---
|
1 2 3 4 5
|
--- title: 標簽 date: 2016-10-21 11:59:10 type: "tags" ---
|
注意:如果有啟用多說 或者 Disqus 評論,默認頁面也會帶有評論。需要關閉的話,請添加字段 comments 並將值設置為 false,如:
1 2 3 4 5 6
|
--- title: 分類 date: 2016-10-21 11:59:10 type: "categories" comments: false ---
|
1 2 3 4 5 6
|
--- title: 標簽 date: 2016-10-21 11:59:10 type: "tags" comments: false ---
|
步驟三
在菜單中添加鏈接。編輯 yilia/_config.yml
(我用的是 yilia 主題),添加 categories | tags 到 menu 中,如下:
1 2 3 4 5
|
menu: home: / archives: /archives categories: /categories tags: /tags
|
步驟四 【這一步非常重要!!!】
找到 layout/_partial/article.ejs
(我用的是 yilia 主題)
然后找到 <div class="article-entry" itemprop="articleBody">
這一行
這個 div 里面的內容全部替換為:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<% if (page.type === "tags") { %> <div class="tag-cloud"> <div class="tag-cloud-title"> <%- _p('counter.tag_cloud', site.tags.length) %> </div>
<div class="tag-cloud-tags"> <%- tagcloud({ min_font: 12, max_font: 30, amount: 200, color: true, start_color: '#ccc', end_color: '#111' }) %> </div> </div>
<% } else if (page.type === 'categories') { %>
<div class="category-all-page"> <div class="category-all-title"> <%- _p('counter.categories', site.categories.length) %> </div> <div class="category-all"> <%- list_categories() %> </div> </div>
<% } else { %>
<% if (post.excerpt && index){ %> <%- post.excerpt %> <% } else { %> <%- post.content %> <% } %> <% } %>
|
步驟五
修改樣式,如果覺得不好看,自己改喜歡的樣式
找到 yilia/source/css/_partial/article.styl
在最后面添加下面的 css 代碼
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*tag-cloud*/ .tag-cloud { text-align: center; margin-top: 50px; } .tag-cloud a { display: inline-block; margin: 10px; } .tag-cloud-title { font-weight: 700; font-size: 24px; } .tag-cloud-tags { margin-top: 15px; a { display: inline-block; text-decoration: none; font-weight: normal; font-size: 10px; color: #fff; line-height: normal; padding: 5px 5px 5px 10px; position: relative; border-radius: 0 5px 5px 0; font-family: Menlo, Monaco, "Andale Mono", "lucida console", "Courier New", monospace; &:hover { opacity: 0.8; } &:before { content: " "; width: 0; height: 0; position: absolute; top: 0; left: -18px; border: 9px solid transparent; } &:after { content: " "; width: 4px; height: 4px; border-radius: 4px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .3); position: absolute; top: 7px; left: 2px; } } a.color1 { background: #FF945C; &:before { border-right-color: #FF945C; } } a.color2 { background: #F5C7B7; &:before { border-right-color: #F5C7B7; } } a.color3 { background: #BA8F6C; &:before { border-right-color: #BA8F6C; } } a.color4 { background: #CFB7C4; &:before { border-right-color: #CFB7C4; } } a.color5 { background: #7B5D5F; &:before { border-right-color: #7B5D5F; } } }
/*category-all-page*/ .category-all-page { margin-top: 50px; .category-all-title { font-weight: 700; font-size: 24px; text-align: center; } .category-list-item:after { content: ''; clear: both; display: table; } .category-list-count { float: right; margin-left: 5px; } .category-list-count:before { content: '一共 '; } .category-list-count:after { content: ' 篇文章'; } }
|