Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #12 from youpy/youpy

  • Loading branch information...
commit 9338fac7787f038485048d064560f8d538047814 2 parents a1f8ec3 + cfb4f1b
@mizzy authored
Showing with 52 additions and 2 deletions.
  1. +2 −2 index.tx
  2. +49 −0 misc/clojure.rb
  3. +1 −0  webiblo.pl
View
4 index.tx
@@ -17,10 +17,10 @@
<li><a href="[% chapter.href %]">[% chapter.title %]</a></li>
<ul>
[% FOREACH section IN chapter.sections -%]
- <li><a href="[% section.href %]">[% section.title %]</li>
+ <li><a href="[% section.href %]">[% section.title %]</a></li>
<ul>
[% FOREACH subsection IN section.subsections -%]
- <li><a href="[% subsection.href %]">[% subsection.title %]</li>
+ <li><a href="[% subsection.href %]">[% subsection.title %]</a></li>
[% END %]
</ul>
[% END -%]
View
49 misc/clojure.rb
@@ -0,0 +1,49 @@
+%w/uri json nokogiri curb cgi/.each {|g| require g }
+
+root = 'http://clojure.org/'
+book = {
+ :title => 'Clojure',
+ :authors => [
+ 'Rich Hickey'
+ ],
+ :cover_image => 'http://clojure.org/space/showimage/clojure-icon.gif',
+ :content_xpath => '//div[@id="content_view"]',
+ :exclude_xpath => '//div[@id="toc"]',
+ :chapters => []
+}
+
+def curl(url)
+ c = Curl::Easy.new(url.to_s)
+ c.follow_location = true
+ c.perform
+ c.body_str
+end
+
+def sections(url)
+ sections = []
+ doc = Nokogiri::HTML(curl(url))
+ doc.xpath('//div[@id="toc"]//a').each do |a|
+ if a[:href] =~ /^#/
+ sections << {
+ :uri => url.to_s + a[:href],
+ :title => a.text
+ }
+ end
+ end
+
+ sections
+end
+
+doc = Nokogiri::HTML(curl(root))
+doc.xpath('//div[@class="WikiCustomNav WikiElement wiki"]//a').each do |a|
+ next if a[:href] =~ /^http/
+ chapter_url = URI(root) + a[:href]
+ chapter = {
+ :uri => chapter_url,
+ :title => a.text,
+ #:sections => sections(chapter_url)
+ }
+ book[:chapters] << chapter
+end
+
+puts book.to_json
View
1  webiblo.pl
@@ -88,6 +88,7 @@ sub get_content {
my $fragment = $uri->fragment;
$file =~ s/\..+/.html/ unless $file =~ /\.html$/;
+ $file .= '.html' unless $file =~ /\.html$/; # add .html if no extension
$object->{file} = $file;
$object->{href} = $fragment ? "$file#$fragment" : $file;
Please sign in to comment.
Something went wrong with that request. Please try again.