Skip to content

Commit

Permalink
Merge pull request #12 from youpy/youpy
Browse files Browse the repository at this point in the history
  • Loading branch information
mizzy committed Apr 4, 2012
2 parents a1f8ec3 + cfb4f1b commit 9338fac
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.tx
Expand Up @@ -17,10 +17,10 @@
<li><a href="[% chapter.href %]">[% chapter.title %]</a></li> <li><a href="[% chapter.href %]">[% chapter.title %]</a></li>
<ul> <ul>
[% FOREACH section IN chapter.sections -%] [% FOREACH section IN chapter.sections -%]
<li><a href="[% section.href %]">[% section.title %]</li> <li><a href="[% section.href %]">[% section.title %]</a></li>
<ul> <ul>
[% FOREACH subsection IN section.subsections -%] [% FOREACH subsection IN section.subsections -%]
<li><a href="[% subsection.href %]">[% subsection.title %]</li> <li><a href="[% subsection.href %]">[% subsection.title %]</a></li>
[% END %] [% END %]
</ul> </ul>
[% END -%] [% END -%]
Expand Down
49 changes: 49 additions & 0 deletions 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
1 change: 1 addition & 0 deletions webiblo.pl
Expand Up @@ -88,6 +88,7 @@ sub get_content {
my $fragment = $uri->fragment; my $fragment = $uri->fragment;


$file =~ s/\..+/.html/ unless $file =~ /\.html$/; $file =~ s/\..+/.html/ unless $file =~ /\.html$/;
$file .= '.html' unless $file =~ /\.html$/; # add .html if no extension
$object->{file} = $file; $object->{file} = $file;
$object->{href} = $fragment ? "$file#$fragment" : $file; $object->{href} = $fragment ? "$file#$fragment" : $file;


Expand Down

0 comments on commit 9338fac

Please sign in to comment.