blog_helper 0.0.5 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +86 -2
- data/Rakefile +1 -1
- data/lib/blog_helper.rb +21 -8
- metadata +4 -4
data/README.md
CHANGED
@@ -9,7 +9,7 @@ This a a collection of tools usable in both platforms.
|
|
9
9
|
- tag your posts
|
10
10
|
- use seo friendly page titles
|
11
11
|
- use the disqus comment counter
|
12
|
-
- a workaround for
|
12
|
+
- a workaround for serious allowing you to use generic yaml fields
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
@@ -23,6 +23,7 @@ Please follow the instrucions there to do so.
|
|
23
23
|
|
24
24
|
Piece of cake, again: all you have to do is use `<% require 'blog_helper'%>` in your .rhtml or .erb file and call the corresponding methods.
|
25
25
|
|
26
|
+
### SEO friendly titles
|
26
27
|
For example, to use seo friendly titles, your layout.rhtml should be looking like this:
|
27
28
|
|
28
29
|
|
@@ -30,7 +31,7 @@ For example, to use seo friendly titles, your layout.rhtml should be looking lik
|
|
30
31
|
<html>
|
31
32
|
<head>
|
32
33
|
<% require 'blog_helper'
|
33
|
-
page_title = BlogHelper::
|
34
|
+
page_title = BlogHelper::seo_friendly_title(@path, title, 'yourSitesTitle.com')
|
34
35
|
%>
|
35
36
|
.
|
36
37
|
.
|
@@ -40,3 +41,86 @@ For example, to use seo friendly titles, your layout.rhtml should be looking lik
|
|
40
41
|
.
|
41
42
|
.
|
42
43
|
.
|
44
|
+
### Tags
|
45
|
+
Adding the tagging feature requires the _toto_prerelease_ as mentioned above, since we need the http request to apply our little hack.
|
46
|
+
|
47
|
+
To add a list of tags to your article, just use a custom yaml attribute:
|
48
|
+
|
49
|
+
title: The Wonderful Wizard of Oz
|
50
|
+
author: Lyman Frank Baum
|
51
|
+
date: 1900/05/17
|
52
|
+
tags: hacks, love, rock 'n' roll
|
53
|
+
|
54
|
+
Dorothy lived in the midst of the great Kansas prairies, with Uncle Henry,
|
55
|
+
who was a farmer, and Aunt Em, who was the farmer's wife.
|
56
|
+
|
57
|
+
Next, you need a place to show the tag links, for example the index.rhtml:
|
58
|
+
|
59
|
+
<section id="articles">
|
60
|
+
<% require 'blog_helper' %>
|
61
|
+
<% for article in articles[0...10] %>
|
62
|
+
<article class="post">
|
63
|
+
<header>
|
64
|
+
<h1><a href="<%= article.path %>"><%= article.title %></a></h1>
|
65
|
+
<span class="descr"><%= article.date %></span><% 10.times { %> <%}%>
|
66
|
+
<span class="tags">
|
67
|
+
<%= BlogHelper::tag_link_list(article[:tags]) %>
|
68
|
+
</span><% 10.times { %> <%}%>
|
69
|
+
.
|
70
|
+
.
|
71
|
+
.
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
And again: piece of caked ;-). Now all we need to add is a page that displays articles belonging to a ceratin tag:
|
76
|
+
|
77
|
+
Create a page called `tagged.rhtml` in your `templates/pages` directory that looks like this:
|
78
|
+
|
79
|
+
<%#
|
80
|
+
# search given tags...
|
81
|
+
%>
|
82
|
+
|
83
|
+
<%
|
84
|
+
require 'cgi'
|
85
|
+
require 'blog_helper'
|
86
|
+
|
87
|
+
desired_tag = env["QUERY_STRING"]
|
88
|
+
if desired_tag
|
89
|
+
start = desired_tag.index("=")
|
90
|
+
stop = desired_tag.index("&")
|
91
|
+
stop = 0 unless stop
|
92
|
+
desired_tag = desired_tag[start+1..stop-1]
|
93
|
+
desired_tag = CGI::unescape(desired_tag)
|
94
|
+
end
|
95
|
+
|
96
|
+
%>
|
97
|
+
<h1>Posts filed under '<%= desired_tag %>': </h1>
|
98
|
+
<ul>
|
99
|
+
|
100
|
+
<% @articles.select do |a|
|
101
|
+
tags = BlogHelper::csv_to_array(a[:tags])
|
102
|
+
tags.include?(desired_tag) if tags
|
103
|
+
end.each do |article| %>
|
104
|
+
<li>
|
105
|
+
<span class="descr"><a href="<%= article.path %>" alt="<%= article.title %>"><%= article.title %></a><br/></span>
|
106
|
+
</li>
|
107
|
+
<% end %>
|
108
|
+
</ul>
|
109
|
+
<br/>
|
110
|
+
|
111
|
+
Now, you did most likely implement a tag listing on your toto blog. Congrats!
|
112
|
+
|
113
|
+
BTW: part of my to dos is encapsulating the tag parsing process so you won't have to fiddle around with too much ruby code here...
|
114
|
+
|
115
|
+
### shor url (via bit.ly)
|
116
|
+
|
117
|
+
short_url = BlogHelper::short_url_bitly(<url>, <bit.ly login nam>, <bit.ly api key>)
|
118
|
+
|
119
|
+
|
120
|
+
### disqus comment counter
|
121
|
+
|
122
|
+
TBD... I have to refer to the source & ri for now.
|
123
|
+
|
124
|
+
### serious custom yaml field reader
|
125
|
+
|
126
|
+
TBD... I have to refer to the source & ri for now.
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ require 'rake/testtask'
|
|
12
12
|
|
13
13
|
spec = Gem::Specification.new do |s|
|
14
14
|
s.name = 'blog_helper'
|
15
|
-
s.version = '0.0.
|
15
|
+
s.version = '0.0.8'
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.extra_rdoc_files = ['README.md', 'LICENSE']
|
18
18
|
s.summary = 'Some handy helpers for serious, toto and the likes...'
|
data/lib/blog_helper.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
|
1
6
|
# Some useful feature for serious, toto and the likes. Basically, any ruby based blog or site.
|
2
7
|
module BlogHelper
|
3
8
|
# create a list of links to tagged articles, default link_format: <code>%&<a href="/tagged?tag=#{tag}" alt="articles concerning #{tag}" >#{tag}</a> &</code>
|
@@ -29,14 +34,13 @@ module BlogHelper
|
|
29
34
|
end
|
30
35
|
page_title
|
31
36
|
end
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
37
|
+
#Generates javascript to include to the bottom of your index page.
|
38
|
+
#Appending '#disqus_thread' to the end of permalinks will replace the text of these links with the comment count.
|
39
|
+
#
|
40
|
+
#For example, you may have a link with this HTML: <code><a href="http://example.com/my_article.html#disqus_thread">Comments</a> </code> The comment count code will replace the text "Comments" with the number of comments on the page
|
41
|
+
#
|
42
|
+
#(see http://disqus.com/comments/universal/ for details)
|
43
|
+
#
|
40
44
|
def BlogHelper.disqus_comment_count_js(disqus_shortname)
|
41
45
|
%&
|
42
46
|
<script type="text/javascript">
|
@@ -50,4 +54,13 @@ module BlogHelper
|
|
50
54
|
|
51
55
|
& if disqus_shortname
|
52
56
|
end
|
57
|
+
# Retrieve bit.ly shortened url
|
58
|
+
def BlogHelper.short_url_bitly(url, login, api_key)
|
59
|
+
if api_key != "" && login != ""
|
60
|
+
rest_call=%{http://api.bit.ly/v3/shorten?login=#{login}&apikey=#{api_key}&longUrl=#{url}&format=txt}
|
61
|
+
Net::HTTP::get(URI.parse(rest_call))
|
62
|
+
else
|
63
|
+
url #fallback: return url to shorten - or nil if it isn't set
|
64
|
+
end
|
65
|
+
end
|
53
66
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blog_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Sven Kr\xC3\xA4uter"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-16 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|