DSIW

Alles was interessant ist... (Linux, Programmierung, Datenschutz, Medien, uvm.)

Tags zu Octopress hinzufügen

| Comments

Als ich meinen Blog von Wordpress nach Octopress migriert hatte, habe ich auch gleich alle Tags der Wordpress-Artikel mit migriert. Allerdings gibt es die Funktionalität von Tags nicht bei Octopress, sodass ich nachhelfen musste. Welche Veränderungen dafür gemacht werden müssen, wird in diesem Artikel erklärt.

Ich habe mich an diesen Pull Request auf GitHub gehalten. Dort wurden alle nötigen Veränderungen vorgenommen. Welche Dateien hinzukamen oder verändert wurden ist im Diff dargestellt.

Skript zum Herunterladen der Dateien

Damit die neu hinzu gekommenen Dateien nicht von Hand installiert werden müssen, stellt ich hier ein Skript zur Verfügung, dass das macht.

(install_files_op-tags.sh) download
1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

cd $1
# check if you are in the right directory
test -d plugins || exit 1
test -d source  || exit 1

curl https://raw.github.com/tedkulp/octopress/tag-cloud/.themes/classic/source/_layouts/tag_index.html > source/_layouts/tag_index.html
curl https://raw.github.com/tedkulp/octopress/tag-cloud/plugins/tag_generator.rb > plugins/tag_generator.rb

cd -

Beispielhafter Aufruf:

$ ./install_files_op-tags.sh ~/octopress

Damit werden die folgenden Dateien heruntergeladen und an die richtige Stelle in Octopress befördert:

  • tag_cloud.html
  • tag_index.rb
  • tag_cloud.rb
  • tag_generator.rb

Optimierungen

Ich habe es dabei nicht belassen, sondern habe noch weitere Veränderungen durchgeführt. Zum Beispiel wollte ich, dass die Tags am Artikelende nach den Kategorien angezeigt werden. In der Archiv-Ansicht habe ich die Tags auch hinzugefügt.

Außerdem musste ich noch das Plugin related_posts.rb anpassen, damit es funktioniert hat.

Diff

In dem nachfolgenden Diff sind alle Unterschiede erkennbar, die ich durchgeführt habe.

Diff (commit-added-tag-functionality.patch) download
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
diff --git a/_config.yml b/_config.yml
index 1026074..deadf84 100644
--- a/_config.yml
+++ b/_config.yml
@@ -3,7 +3,6 @@
 # ----------------------- #

 url: http://blog.dsiw-it.de
-#url: http://dsiw.aquarius.uberspace.de/blog
 title: DSIW
 subtitle: Alles was interessant ist... (Linux, Programmierung, Datenschutz, Medien, uvm.)
 author: DSIW
@@ -35,10 +34,10 @@ destination: public
 plugins: plugins
 code_dir: downloads/code
 category_dir: categories
-category_title_prefix: "Kategorie: " 
-tag_title_prefix: Tag
+category_title_prefix: "Kategorie: "
+tag_title_prefix: "Tag: "
 tag_page_layout: tag_page
-tag_page_dir: tags
+tag_dir: tags
 markdown: rdiscount
 pygments: false # default python pygments have been replaced by pygments.rb
 markdown_ext: 'markdown,mkd,mkdn,md,octopress'
@@ -53,10 +52,6 @@ excerpt_link: "Weiterlesen →"  # "Continue reading" link text at the bottom
 titlecase: false       # Converts page and post titles to titlecase
 future: false

-# indextank settings
-#indextank_index: my_index
-#indextank_api_url: http://:myapikey@myapi.api.indextank.com
-
 # these values are applied as regular expressions
 indextank_excludes: [index.html, 404.html, ^/secret/]

diff --git a/plugins/related_posts.rb b/plugins/related_posts.rb
index 5085305..5a497d8 100644
--- a/plugins/related_posts.rb
+++ b/plugins/related_posts.rb
@@ -16,11 +16,12 @@ module RelatedPosts
     return [] unless posts.size > 1
     highest_freq = Jekyll::Post.tag_freq(posts).values.max
     related_scores = Hash.new(0)
-    posts.each do |post|
+    posts.clone.each do |post|
+      post = post.clone
       post.tags += post.categories - ['linux']
-      post.tags.each do |tag|
+      post.tags.uniq.each do |tag|
         if self.tags.include?(tag) && post != self
-          cat_freq = Jekyll::Post.tag_freq(posts)[tag]
+          cat_freq = Jekyll::Post.tag_freq(posts.clone)[tag]
           related_scores[post] += (1+highest_freq-cat_freq)
         end
       end
diff --git a/source/_includes/archive_post.html b/source/_includes/archive_post.html
index fef3328..45a0c79 100644
--- a/source/_includes/archive_post.html
+++ b/source/_includes/archive_post.html
@@ -4,5 +4,6 @@
 {% if category != '0' %}
 <footer>
   <span class="categories">posted in {{ post.categories | category_links }}</span>
+  <span class="categories">with {{ post.tags | tag_links }}</span>
 </footer>
 {% endif %}
diff --git a/source/_includes/post/categories.html b/source/_includes/post/categories.html
index 4a98b29..d75dcaa 100644
--- a/source/_includes/post/categories.html
+++ b/source/_includes/post/categories.html
@@ -1,4 +1,11 @@
-{% capture category %}{% if post %}{{ post.categories | category_links | size }}{% else %}{{ page.categories | category_links | size }}{% endif %}{% endcapture %}
+{% capture category %}
+  {% if post %}
+    {{ post.categories | category_links | size }}
+  {% else %}
+    {{ page.categories | category_links | size }}
+  {% endif %}
+{% endcapture %}
+
 {% unless category == '0' %}
 <span class="categories">
   {% if post %}
diff --git a/source/_includes/post/tags.html b/source/_includes/post/tags.html
index 4d265e9..190ba06 100644
--- a/source/_includes/post/tags.html
+++ b/source/_includes/post/tags.html
@@ -1,16 +1,17 @@
-{% capture tag %}{% if post %}{{ post.tags | tag_links | size }}{% else %}{{ page.tags | tag_links | size }}{% endif %}{% endcapture %}
+{% capture tag %}
+  {% if post %}
+    {{ post.tags | tag_links | size }}
+  {% else %}
+    {{ page.tags | tag_links | size }}
+  {% endif %}
+{% endcapture %}
+
 {% unless tag == '0' %}
-<div id="tag_list">
-  Tags: 
-  <ul id="tags_ul">
-    <!--{% if post %}-->
-      <!--{{ post.tags | tag_links }}-->
-    <!--{% else %}-->
-      <!--{{ page.tags | tag_links }}-->
-    <!--{% endif %}-->
-    {% for t in page.tags  %}
-      <li><a href="/tags/{{t}}/">{{t}}</a></li>
-    {% endfor %}
-  </ul>
-</div>
+<span class="categories">
+  {% if post %}
+    {{ post.tags | tag_links }}
+  {% else %}
+    {{ page.tags | tag_links }}
+  {% endif %}
+</span>
 {% endunless %}
diff --git a/source/_layouts/post.html b/source/_layouts/post.html
index d3c42e3..22c1557 100644
--- a/source/_layouts/post.html
+++ b/source/_layouts/post.html
@@ -11,6 +11,7 @@ single: true
       {% include post/author.html %}
       {% include post/date.html %}{% if updated %}{{ updated }}{% else %}{{ time }}{% endif %}
       {% include post/categories.html %}
+      {% include post/tags.html %}
     </p>
     {% unless page.sharing == false %}
       {% include post/sharing.html %}

Bei Fragen oder sonstigen Anregungen, freue ich mich auf einen Kommentar oder eine E-Mail.

Comments