nebel 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +3 -0
  3. data/README.md +5 -0
  4. data/Rakefile +2 -0
  5. data/bin/nebel +193 -0
  6. data/bin/nebel-server +14 -0
  7. data/nebel.gemspec +18 -0
  8. metadata +86 -0
@@ -0,0 +1,6 @@
1
+ .pygments-cache
2
+ .gist-cache
3
+ .twan-cache
4
+ .vimeo-cache
5
+ Gemfile.lock
6
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
@@ -0,0 +1,5 @@
1
+ # Nebel - A static site generator
2
+
3
+ Nebel is a static site generator written by Ruby.
4
+
5
+ Please see [README of nebel-site](https://github.com/mizzy/nebel-site/blob/master/README.md) for details.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $LOAD_PATH.unshift '.'
5
+
6
+ require 'bundler/setup'
7
+ require 'time'
8
+ require 'English'
9
+ require 'yaml'
10
+ require 'fileutils'
11
+ require 'liquid'
12
+ require 'redcarpet'
13
+ require 'optparse'
14
+
15
+ def inject_options(nebelrc)
16
+ extra_args_string = File.open(nebelrc).read
17
+ extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten
18
+ puts "Using #{extra_args.join(" ")} from #{nebelrc}"
19
+ ARGV << extra_args
20
+ ARGV.flatten!
21
+ end
22
+
23
+ nebelrc = File.join(File.expand_path("~"), ".nebelrc")
24
+ inject_options(nebelrc) if File.exist?(nebelrc)
25
+
26
+ options = {
27
+ :base_url => "/blog",
28
+ :archive => false,
29
+ :no_clean_dir => false,
30
+ }
31
+
32
+ OptionParser.new { |opts|
33
+ opts.on('-b', '--base-url [PATH]', String, "Serve website from a given base URL\t(default '/blog')") do |val|
34
+ options[:base_url] = val == "/" ? "" : val
35
+ end
36
+ opts.on('-a', '--archive', "Generate archive pages\t\t\t(default '/archive')") do
37
+ options[:archive] = true
38
+ end
39
+ opts.on('--no-clean-dir', "Doesn't remove files in public dir") do
40
+ options[:no_clean_dir] = true
41
+ end
42
+ opts.on('-h', '--help',"Show this message") do
43
+ puts opts; exit 0
44
+ end
45
+ }.parse!
46
+
47
+ def parse(file)
48
+ if File.read(file['path']) =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
49
+ content = $POSTMATCH
50
+ data = YAML.load($1)
51
+ end
52
+ return content, data
53
+ end
54
+
55
+ unless options[:no_clean_dir]
56
+ Dir.glob('public/*').each do |path|
57
+ `rm -rf #{path}`
58
+ end
59
+ end
60
+
61
+ Dir[File.join('plugins', '*.rb')].each do |f|
62
+ require f
63
+ end
64
+
65
+ posts_dir = File.join(Dir.pwd, 'posts')
66
+
67
+ files = []
68
+ Dir.glob("#{posts_dir}/*").each do |path|
69
+ open(path) {|fh|
70
+ fh.each do |line|
71
+ if line =~ /date: (.+)$/
72
+ date = Time.parse($1)
73
+ files << { 'path' => path, 'date' => date }
74
+ break
75
+ end
76
+ end
77
+ }
78
+ end
79
+
80
+ files = files.sort{|a, b| a['date'] <=> b['date']}
81
+
82
+ pre_entry_date = '0000/00/00'
83
+ cnt = 1
84
+ files.each do |file|
85
+ date = file['date'].strftime('%Y/%m/%d')
86
+ if pre_entry_date == date
87
+ cnt = cnt +1
88
+ else
89
+ cnt = 1
90
+ end
91
+ file['cnt'] = cnt
92
+ file['link'] = sprintf "#{options[:base_url]}/%s/%s", date, cnt.to_s
93
+ pre_entry_date = date
94
+ end
95
+
96
+ pos = 0
97
+ feeds = []
98
+ archives = []
99
+ files.reverse!
100
+ files.each do |file|
101
+ content, data = parse(file)
102
+
103
+ out_dir = File.join('public', file['link'])
104
+
105
+ FileUtils.mkpath(out_dir) unless File.directory?(out_dir)
106
+
107
+ # For compatibility with Jekyll plugins
108
+ site = Class.new do
109
+ def config
110
+ { 'code_dir' => '' }
111
+ end
112
+ def source
113
+ 'codes'
114
+ end
115
+ end.new
116
+
117
+ info = { filters: [Jekyll::Filters], registers: { site: site } }
118
+ content = Liquid::Template.parse(content).render({}, info)
119
+
120
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
121
+ :autolink => true,
122
+ :space_after_headers => true,
123
+ :fenced_code_blocks => true)
124
+ content = markdown.render(content)
125
+
126
+ feeds.push({
127
+ 'title' => data['title'],
128
+ 'content' => content,
129
+ 'date' => file['date'].iso8601,
130
+ 'link' => file['link'],
131
+ }) if pos < 10
132
+
133
+ next_page = files[pos + 1] if pos < files.length - 1
134
+ prev_page = files[pos - 1] if pos > 0
135
+
136
+ include Octopress::Date
137
+ params = {
138
+ 'title' => data['title'],
139
+ 'link' => file['link'],
140
+ 'date' => file['date'],
141
+ 'date_formatted' => Octopress::Date.ordinalize(file['date']),
142
+ 'content' => content,
143
+ 'next_page' => next_page,
144
+ 'prev_page' => prev_page,
145
+ }
146
+
147
+ if options[:archive]
148
+ archives.push({
149
+ 'title' => data['title'],
150
+ 'date_formatted' => Octopress::Date.ordinalize(file['date']),
151
+ 'link' => file['link'],
152
+ })
153
+ end
154
+
155
+ layout = File.read('layouts/post.html')
156
+ post = Liquid::Template.parse(layout).render(params, info)
157
+
158
+ f = File.open(File.join(out_dir, 'index.html'), "w")
159
+ f.write post
160
+ f.close
161
+
162
+ if pos == 0
163
+ params['index'] = true
164
+ layout = File.read('layouts/post.html')
165
+ post = Liquid::Template.parse(layout).render(params, info)
166
+ f = File.open(File.join('public', 'index.html'), "w")
167
+ f.write post
168
+ f.close
169
+ end
170
+
171
+ pos = pos + 1
172
+ end
173
+
174
+ FileUtils.cp_r(Dir.glob('static/*'), 'public')
175
+
176
+ layout = File.read('layouts/atom.xml')
177
+ atom = Liquid::Template.parse(layout).render 'feeds' => feeds
178
+
179
+ f = File.open(File.join('public', 'atom.xml'), "w")
180
+ f.write atom
181
+ f.close
182
+
183
+ if options[:archive]
184
+ layout = File.read('layouts/archive.html')
185
+ archive = Liquid::Template.parse(layout).render 'archives' => archives
186
+
187
+ archive_dir = "public/archive"
188
+ FileUtils.mkdir(archive_dir) unless File.directory?(archive_dir)
189
+
190
+ f = File.open(File.join('public', 'archive', 'index.html'), "w")
191
+ f.write archive
192
+ f.close
193
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'webrick'
4
+
5
+ include WEBrick
6
+
7
+ s = HTTPServer.new(
8
+ Port: 5000,
9
+ DocumentRoot: './public'
10
+ )
11
+
12
+ trap('INT') { s.shutdown }
13
+
14
+ s.start
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "nebel"
5
+ s.version = "0.0.2"
6
+ s.authors = ["Gosuke Miyashita"]
7
+ s.email = ["gosukenator@gmail.com"]
8
+ s.homepage = "https://github.com/mizzy/nebel"
9
+ s.summary = %q{A command line tool for generating a static site.}
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+
15
+ # dependencies
16
+ s.add_dependency 'liquid', '2.2.2'
17
+ s.add_dependency 'redcarpet'
18
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nebel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gosuke Miyashita
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: liquid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.2.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.2.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: redcarpet
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description:
47
+ email:
48
+ - gosukenator@gmail.com
49
+ executables:
50
+ - nebel
51
+ - nebel-server
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - README.md
58
+ - Rakefile
59
+ - bin/nebel
60
+ - bin/nebel-server
61
+ - nebel.gemspec
62
+ homepage: https://github.com/mizzy/nebel
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A command line tool for generating a static site.
86
+ test_files: []