who-needs-wp 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.html ADDED
@@ -0,0 +1,132 @@
1
+ <h1>who-needs-wp</h1>
2
+
3
+ <p><em>Who needs Wordpress?</em></p>
4
+
5
+ <p>The majority of web sites are consumed. Visitors will stumble upon the site, read a few pages (if you're lucky) and then disappear. Normally for every visitor to the site each webpage is generated dynamically. Each visitor has their own version of the web page for that particular moment of time. Is this really necessary? How often does the content on the web site you are visiting change?</p>
6
+
7
+ <p>Take blogs for example. I have a blog written using the excellent Wordpress software. I'm able to write posts within Wordpress and see them appear on the web site without leaving my web browser. My posts are held in a database, when a user requests to view my blog multiple requests are made to the database to build a dynamic page on which contents rarely changes. I create a new blog post every 3 weeks, it seems a bit unnecessary to generate a web page when the content hasn't changed.</p>
8
+
9
+ <p>There is another option. Instead of generating the web site dynamically when the page is requested I can generate the web page whenever the content changes. So whenever I create a new post - I regenerate the site. </p>
10
+
11
+ <p>This has the advantage of serving web pages faster; I use less hosting space; and I cut any unnecessary features which Wordpress provides.</p>
12
+
13
+ <p>The main disadvantage is that user's aren't able to comment on my posts - but this don't matter too much - nobody ever did! ;-)</p>
14
+
15
+ <h2>Getting Started</h2>
16
+
17
+ <p>who-needs-wp is a small Ruby program which helps generate static web sites. To start using who-needs-wp you need to install Ruby. On Ubuntu enter the following into a command prompt:</p>
18
+
19
+ <pre><code>sudo apt-get install ruby ruby-dev rubygems
20
+ </code></pre>
21
+
22
+ <p>You then need to install who-needs-wp by running the following:</p>
23
+
24
+ <pre><code>sudo gem install who-needs-wp
25
+ </code></pre>
26
+
27
+ <p>Ensure that Ruby gems is in your <code>PATH</code> variable by opening <code>~/.bashrc</code> and entering:</p>
28
+
29
+ <pre><code>export PATH=/var/lib/gems/1.8/bin:$PATH
30
+ </code></pre>
31
+
32
+ <p>You'll need to re-load the <code>.bashrc</code> file by using the following command:</p>
33
+
34
+ <pre><code>. ~/.bashrc
35
+ </code></pre>
36
+
37
+ <p>Now create a folder which will host your web site</p>
38
+
39
+ <pre><code>mkdir /var/www/website/
40
+ </code></pre>
41
+
42
+ <p>who-needs-wp stores posts in the <code>posts/</code> folder followed by a folder representing the date of the post. i.e. <code>posts/year/month/day</code>.</p>
43
+
44
+ <p>Create an example post by creating a folder and creating a Markdown file.</p>
45
+
46
+ <pre><code>mkdir /var/www/website/posts/2010/03/15/ --parents
47
+ gedit /var/www/website/posts/2010/03/15/An_example_post.markdown
48
+ </code></pre>
49
+
50
+ <p>The filename will be used as the title for the page - all the underscores will be replaced with spaces.</p>
51
+
52
+ <p>Along with <a href="http://daringfireball.net/projects/markdown/syntax">Markdown Syntax</a> you can also specify the author of the blog post within the file:</p>
53
+
54
+ <pre><code>Author: Your Name
55
+ </code></pre>
56
+
57
+ <p>Before it can generate the site who-needs-wp needs to be configured. Copy the following into <code>/var/www/website/.who-needs-wp.yaml</code></p>
58
+
59
+ <pre><code>---
60
+ :url: /website/test
61
+ :title: An example blog
62
+ :author: Your Name
63
+ </code></pre>
64
+
65
+ <p>These are the properties which are used to generate the website:</p>
66
+
67
+ <ul>
68
+ <li><code>url</code> - The base URL of the website</li>
69
+ <li><code>title</code> - A title for the index of your site</li>
70
+ <li><code>author</code> - When a author is not specified within the post this author is displayed</li>
71
+ </ul>
72
+
73
+ <p>Now you can generate your site:</p>
74
+
75
+ <pre><code>who-needs-wp .
76
+ </code></pre>
77
+
78
+ <p>And view the blog at the following URL:</p>
79
+
80
+ <pre><code>http://localhost/website/
81
+ </code></pre>
82
+
83
+ <h2>Overriding Templates</h2>
84
+
85
+ <p>You will probably find that the templates used by who-needs-wp don't quite match your requirements. You can override any of the templates by creating a <code>templates</code> folder. You can copy the existing templates from the gem as a starting point. The templates are stored within the <code>/var/lib/gems/1.8/gems/who-needs-wp-0.1.0/lib/who-needs-wp/templates/</code>. </p>
86
+
87
+ <h2>Applying alternative styles</h2>
88
+
89
+ <p>You can specify an additional stylesheet by using the <code>-s</code> or <code>--stylesheet</code> option to the who-needs-wp command.</p>
90
+
91
+ <h2>Twitter</h2>
92
+
93
+ <p>who-needs-wp can place a <a href="http://twitter.com/">Twitter</a> stream in the side bar. This can either be a search or an individual user's feed.</p>
94
+
95
+ <p>Modifying <code>.who-needs-wp.yaml</code> and add:</p>
96
+
97
+ <pre><code>:twitter:
98
+ :user: &lt;your twitter user&gt;
99
+ :search: &lt;your twitter search&gt;
100
+ </code></pre>
101
+
102
+ <h2>Delicious</h2>
103
+
104
+ <p>who-needs-wp can also display a list of bookmarks from <a href="http://del.icio.us/">Delicious</a>. Modify <code>.who-needs-wp.yaml</code> and add:</p>
105
+
106
+ <pre><code>:delicious:
107
+ :user: &lt;your delicious username&gt;
108
+ </code></pre>
109
+
110
+ <h2>Google Analytics</h2>
111
+
112
+ <p>To enable Google Analytics you need to specify your web property ID in <code>.who-needs-wp.yaml</code>. For example:</p>
113
+
114
+ <pre><code>:google_analytics: UA-XXXXXXXX
115
+ </code></pre>
116
+
117
+ <h2>Syntax Highlighting</h2>
118
+
119
+ <p>who-needs-wp will syntax highlight your code snippets using <a href="http://github.com/nakajima/makers-mark">Makers-Mark</a> and <a href="http://pygments.org/">Pygments</a></p>
120
+
121
+ <h2>Migration from Wordpress</h2>
122
+
123
+ <p>Packaged with who-needs-wp is a simple script called wordpress2wnwp which aids migrating from Wordpress. wordpress2wnwp exports posts from a MySQL database and outputs them in the who-needs-wp filing structure. It also generates Apache2 <code>RewriteRule</code>s which rewrite any Wordpress URLs to who-needs-wp.</p>
124
+
125
+ <p>To find more information on wordpress2wnwp enter the following command:</p>
126
+
127
+ <pre><code>wordpress2wnwp -h
128
+ </code></pre>
129
+
130
+ <h3>Copyright</h3>
131
+
132
+ <p>Copyright (c) 2010 Owen Griffin. See LICENSE for details.</p>
data/README.md CHANGED
@@ -101,7 +101,10 @@ To enable Google Analytics you need to specify your web property ID in `.who-nee
101
101
 
102
102
  ## Syntax Highlighting
103
103
 
104
- who-needs-wp will syntax highlight your code snippets using [Makers-Mark][MakersMark] and [Pygments][Pygments]
104
+ who-needs-wp will syntax highlight your code snippets using [Makers-Mark][MakersMark] and [Pygments][Pygments]. You will need to ensure that Pygments is installed.
105
+
106
+ sudo apt-get install python-setuptools
107
+ sudo easy_install pygments
105
108
 
106
109
  ## Migration from Wordpress
107
110
 
data/bin/who-needs-wp CHANGED
@@ -47,6 +47,17 @@ Choice.options do
47
47
  default options[:author]
48
48
  end
49
49
 
50
+ option :upload do
51
+ short '-u'
52
+ long '--upload'
53
+ desc 'Upload the output to an FTP address.'
54
+ end
55
+
56
+ option :remote_addr do
57
+ long '--remote-addr=username'
58
+ desc "Location to upload the output. To enable specify the --upload option. (Default: \"#{options[:ftp]}\")"
59
+ end
60
+
50
61
  option :help do
51
62
  long '--help'
52
63
  desc 'Show this message'
data/bin/wordpress2wnwp CHANGED
@@ -98,7 +98,7 @@ class Wordpress2WNWP
98
98
 
99
99
  # Returns a list of parent post identifiers
100
100
  def self.parent_posts
101
- results = @database.query("SELECT DISTINCT post_parent FROM #{@table_name}")
101
+ results = @database.query("SELECT id FROM #{@table_name} WHERE post_type ='post'")
102
102
  posts = []
103
103
  while row = results.fetch_row do
104
104
  posts << row[0]
@@ -110,14 +110,14 @@ class Wordpress2WNWP
110
110
  def self.latest_posts(parents)
111
111
  posts = []
112
112
  parents.each do |post_id|
113
- results = @database.query("SELECT post_title, post_date, post_content FROM #{@table_name} WHERE post_parent = '#{post_id}' ORDER BY ID DESC LIMIT 1")
113
+ results = @database.query("SELECT post_title, post_date, post_content FROM #{@table_name} WHERE post_parent = '#{post_id}' AND post_type='revision' ORDER BY ID DESC LIMIT 1")
114
114
  row = results.fetch_row
115
115
  posts << {
116
116
  :id => post_id,
117
117
  :title => row[0],
118
118
  :date => Date.parse(row[1]),
119
119
  :content => row[2]
120
- }
120
+ } if row != nil
121
121
  end
122
122
  return posts
123
123
  end
@@ -137,16 +137,31 @@ class Wordpress2WNWP
137
137
 
138
138
  # Generate a list of Apache2 rewrite rules
139
139
  def self.generate_rewrites(posts)
140
- puts "Re-write rules for Apache2:"
141
- posts.each do |post|
142
- results = @database.query("SELECT guid FROM #{@table_name} WHERE post_parent='#{post[:id]}'")
143
- while row = results.fetch_row do
144
- if row[0] =~ /p=([0-9]+)/
145
- guid = $1
146
- puts "RewriteCond %{QUERY_STRING} p=#{guid}"
147
- puts "RewriteRule ^#{@options[:url]}$ #{@options[:url]}posts/#{post[:filename]} [L]"
140
+ File.open('.htaccess', 'w') do |file|
141
+ # Set up redirects
142
+ file.puts "RewriteEngine On"
143
+ base = @options[:url]
144
+ base = '/' if base.empty?
145
+ file.puts "RewriteBase #{base}"
146
+
147
+ # Re-write for RSS 2.0 feed
148
+ file.puts "RewriteCond %{QUERY_STRING} ^feed=rss2$"
149
+ file.puts "RewriteRule ^.*$ #{@options[:url]}/posts.rss?feed= [L]"
150
+ # Rewrites for all posts
151
+ posts.each do |post|
152
+ file.puts "RewriteCond %{QUERY_STRING} ^p=#{post[:id]}$"
153
+ file.puts "RewriteRule ^.*$ #{@options[:url]}/posts/#{post[:filename]}?p= [L]"
154
+ results = @database.query("SELECT guid FROM #{@table_name} WHERE post_parent='#{post[:id]}'")
155
+ while row = results.fetch_row do
156
+ if row[0] =~ /p=([0-9]+)/
157
+ guid = $1
158
+ file.puts "RewriteCond %{QUERY_STRING} ^p=#{guid}$"
159
+ file.puts "RewriteRule ^.*$ #{@options[:url]}/posts/#{post[:filename]}?p= [R,L]"
160
+ end
148
161
  end
162
+
149
163
  end
164
+
150
165
  end
151
166
  end
152
167
  end
@@ -0,0 +1,6 @@
1
+ #!/bin/ruby
2
+
3
+ prefix = ARGV[3]
4
+ DB = Sequel.connect('postgres://localhost/#{ARGV[0]}?user=#{ARGV[1]}&password=#{ARGV[2]}')
5
+
6
+ dataset = DB.from('wp_#{prefix}_posts')
data/lib/who-needs-wp.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- coding: undecided -*-
1
2
  require 'rubygems'
2
3
  require 'rdiscount'
3
4
  require 'haml'
@@ -8,6 +9,8 @@ require 'sass'
8
9
  require 'makers-mark'
9
10
  require 'logger'
10
11
  require 'rss/maker'
12
+ require 'net/ssh'
13
+ require 'net/sftp'
11
14
  require 'who-needs-wp/css.rb'
12
15
  require 'who-needs-wp/twitter.rb'
13
16
  require 'who-needs-wp/delicious.rb'
@@ -28,13 +31,16 @@ module WhoNeedsWP
28
31
  # Generate the site with the specified options
29
32
  def self.generate(options)
30
33
  @options = options
34
+ if @options[:url] == '/'
35
+ @options[:url] = ''
36
+ end
31
37
  self.load_templates
32
38
  self.load_posts
33
39
  self.load_pages
34
40
  self.recentposts
35
41
  self.page_index
36
- # self.twitter
37
- # self.delicious
42
+ self.twitter
43
+ self.delicious
38
44
  self.generate_posts
39
45
  self.generate_pages
40
46
  self.index
@@ -42,6 +48,9 @@ module WhoNeedsWP
42
48
  self.css
43
49
  self.rss("posts.rss")
44
50
  self.atom("posts.atom")
51
+ if @options[:upload]
52
+ self.upload
53
+ end
45
54
  end
46
55
 
47
56
  # Generate the index page for the blog
@@ -64,4 +73,66 @@ module WhoNeedsWP
64
73
  :options => @options
65
74
  }), "All Posts")
66
75
  end
76
+
77
+ def self.upload
78
+ match = @options[:remote_addr].match(/(.*)@(.*):(.*)/)
79
+ username = match[1]
80
+ host = match[2]
81
+ remote_path = match[3]
82
+ # Replace the tilda with the full path for home
83
+ remote_path = "/home/#{username}/" + remote_path[1..remote_path.length] if remote_path =~ /^~.*$/
84
+ local_path = Dir.pwd
85
+ permissions = {
86
+ :directory => 0755,
87
+ :file => 0644
88
+ }
89
+ Net::SFTP.start(host, username) do |sftp|
90
+ Dir.glob("**/*") do |filename|
91
+ basename = File.basename(filename)
92
+ if basename =~ /^\..*$/ or
93
+ basename =~ /.*\.markdown$/ or
94
+ basename =~ /^.*~$/ or
95
+ basename =~ /^\#.*\#$/
96
+ @logger.debug "Skipping #{filename}"
97
+ else
98
+ remote_filename = remote_path + filename.sub(local_path, '')
99
+ @logger.debug "Remote filename = #{remote_filename}"
100
+
101
+ # If the directory does not exist then create it
102
+ begin
103
+ if File.directory? filename
104
+ remote_directory = remote_filename
105
+ else
106
+ remote_directory = File.dirname(remote_filename)
107
+ end
108
+ sftp.stat!(remote_directory)
109
+ rescue Net::SFTP::StatusException
110
+ @logger.debug "#{remote_directory} does not exist"
111
+ sftp.mkdir!(remote_directory, :permissions => permissions[:directory])
112
+ end
113
+
114
+ if not File.directory? filename
115
+ # If the file does not exist then create it
116
+ begin
117
+ status = sftp.stat!(remote_filename)
118
+ rescue Net::SFTP::StatusException
119
+ @logger.debug "#{remote_filename} does not exist"
120
+ sftp.upload!(filename, remote_filename)
121
+ sftp.setstat(remote_filename, :permissions => permissions[:file])
122
+ next
123
+ end
124
+
125
+ # If the local file has changed then upload it
126
+ if File.stat(filename).mtime > Time.at(status.mtime)
127
+ @logger.debug "Copying #{filename} to #{remote_filename}"
128
+ sftp.upload!(filename, remote_filename)
129
+ else
130
+ @logger.debug "Skipping #{filename}"
131
+ end
132
+ end
133
+ end
134
+ end
135
+ @logger.debug "Disconnecting from remote server"
136
+ end
137
+ end
67
138
  end
@@ -3,7 +3,7 @@
3
3
  %h2.title
4
4
  %a{:href => "#{options[:url]}/#{post[:filename][:generated]}"}= post[:title]
5
5
  .date
6
- = post[:created_at].strftime('%Y-%m-%d')
6
+ = post[:created_at].strftime("%B %d, %Y")
7
7
  .author
8
8
  by
9
9
  = post[:author]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 1
9
- version: 0.5.1
8
+ - 2
9
+ version: 0.5.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Owen Griffin
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-26 00:00:00 +00:00
17
+ date: 2010-03-27 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -118,12 +118,14 @@ dependencies:
118
118
  description: A static web site generator.
119
119
  email: owen.griffin@gmail.com
120
120
  executables:
121
+ - wordpress2wnwp~
121
122
  - wordpress2wnwp
122
123
  - who-needs-wp
123
124
  extensions: []
124
125
 
125
126
  extra_rdoc_files:
126
127
  - LICENSE
128
+ - README.html
127
129
  - README.md
128
130
  files:
129
131
  - lib/who-needs-wp.rb
@@ -149,6 +151,7 @@ files:
149
151
  - lib/who-needs-wp/templates/twitter.haml
150
152
  - lib/who-needs-wp/twitter.rb
151
153
  - LICENSE
154
+ - README.html
152
155
  - README.md
153
156
  has_rdoc: true
154
157
  homepage: http://github.com/owengriffin/who-needs-wp