Skip to content

Commit 7a5303d

Browse files
committed
Merge branch 'migrate-book-to-hugo'
This topic branch's purpose is to prepare for rendering the ProGit book and its translations from the various external repositories' contents. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 33e371c + c058546 commit 7a5303d

File tree

585 files changed

+801
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

585 files changed

+801
-434
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ source "https://rubygems.org"
44

55
gem "octokit"
66
gem "rss"
7+
gem "asciidoctor", "~> 2.0.0"
8+
gem "nokogiri"

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,29 @@ Now you need to get the latest downloads for the downloads pages:
101101

102102
## Update the ProGit book
103103

104-
(TODO!)
105-
Now you'll probably want some book data. You'll have
106-
to have access to the [Pro Git project on GitHub](https://github.com/progit/progit2) through the API.
104+
First, you will have to get the necessary prerequisites:
107105

108-
$ export GITHUB_API_TOKEN=github_personal_auth_token
109-
$ rake remote_genbook2
106+
$ bundler install
107+
108+
Now you'll probably want some book data.
109+
110+
You'll have to get the book content from a repository on your computer by specifying the path:
110111

111-
If you have 2FA enabled, you'll need to create a [Personal Access Token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).
112+
$ git clone https://github.com/progit/progit2-fr ../progit2-fr
113+
$ ruby ./script/update-book2.rb fr ../progit2-fr
112114

113-
That will generate the book content from the Asciidoc files fetched from the online repository and post it to the Rails server database. You can select a specific language by indicating it in the `GENLANG` environment variable:
115+
That will generate the book content from the Asciidoc files and write the files to the local tree, ready to be committed and served via Hugo.
116+
117+
Alternatively, you need to have access to the [Pro Git project on GitHub](https://github.com/progit/progit2) through the API.
118+
119+
$ export GITHUB_API_TOKEN=github_personal_auth_token
120+
$ ruby ./script/update-book2.rb en
114121

115-
$ GENLANG=zh rake remote_genbook2
122+
If you have 2FA enabled, you'll need to create a [Personal Access Token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).
116123

117-
Alternatively, you can get the book content from a repository on your computer by specifying the path in the `GENPATH` environment variable to the `local_genbook2` target:
124+
If you want to build the book for all available languages, just omit the language code parameter:
118125

119-
$ GENLANG=fr GENPATH=../progit2-fr rake local_genbook2
126+
$ ruby ./script/update-book2.rb
120127

121128
## Contributing
122129

app/models/book.rb

Lines changed: 0 additions & 50 deletions
This file was deleted.

doc/README_FOR_APP

Lines changed: 0 additions & 2 deletions
This file was deleted.

doc/css-stats.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

hugo.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ markup:
1212
goldmark:
1313
renderer:
1414
unsafe: true
15+
module:
16+
mounts:
17+
- source: content
18+
target: content
19+
- source: static
20+
target: static
21+
- source: data
22+
target: data
23+
- source: external/book/data/book
24+
target: data/book
25+
- source: external/book/content/book
26+
target: content/book
27+
- source: external/book/static/book
28+
target: static/book
1529
params:
1630
hugo_version: 0.134.3
1731
pagefind_version: 1.1.1

layouts/_default/baseof.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,33 @@ <h1>Redirecting&hellip;</h1>
7272
{{ partial "footer.html" . }}
7373
</div> <!-- .inner -->
7474
</div> <!-- #content-wrapper -->
75+
{{ else if (isset .Params "book") }}
76+
{{ .Scratch.Set "book" (index .Site.Data.book .Params.book.language_code) }}
77+
<div class="inner">
78+
<div id="content-wrapper">
79+
{{ partial "sidebar.html" . }}
80+
<div id="content">
81+
{{ if isset .Params.book "front_page" }}
82+
{{ partial "book-front-page.html" . }}
83+
{{ else }}
84+
<div id="book-chapters">
85+
{{ partial "chapters.html" . }}
86+
87+
<span class="light" id="edition">
88+
2nd Edition
89+
</span>
90+
</div>
91+
<div id="main" data-pagefind-filter="category:book" data-pagefind-body class="book edition2">
92+
<h1>{{ .Params.book.section.cs_number }} {{ .Params.book.chapter.title }} - {{ .Params.book.section.title }}</h1>
93+
<div>
94+
{{ .Content }}
95+
</div>
96+
</div>
97+
{{ end }}
98+
</div>
99+
</div>
100+
{{ partial "footer.html" . }}
101+
</div>
75102
{{ else }}
76103
<div class="inner">
77104
<div id="content-wrapper">
Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,27 @@
1-
<%- @section = 'documentation' %>
2-
<%- @subsection = 'book' %>
3-
<%- @page_title = "Git - Book" %>
4-
5-
<% content_for :sidebar do %>
6-
<%= render 'translations' %>
7-
<% end %>
8-
91
<div id='main'>
102
<h1>Book</h1>
11-
<% if @book.edition == 2 %>
12-
<div class="book-wrapper">
13-
<img src="{{ relURL "images/progit2.png" }}" width="118" height="157"/>
14-
<div style="light">2nd Edition (2014)</div>
15-
<% if (@book.ebook_pdf || @book.ebook_epub || @book.ebook_mobi) %>
3+
<div class="book-wrapper">
4+
<img src="{{ relURL "images/progit2.png" }}" width="118" height="157"/>
5+
<div style="light">2nd Edition (2014)</div>
6+
{{ if (or (isset .Params.book "ebook_pdf") (isset .Params.book "ebook_epub") (isset .Params.book "ebook_mobi")) }}
167
<div class="ebook-download">
178
<h2>Download Ebook</h2>
189
<div class="ebooks">
19-
<% if @book.ebook_pdf %>
20-
<a href="<%= @book.ebook_pdf %>"><img width="50px" src="{{ relURL "images/pdf.png" }}"/></a>
21-
<% end %>
22-
<% if @book.ebook_epub %>
23-
<a href="<%= @book.ebook_epub %>"><img width="50px" src="{{ relURL "images/epub.png" }}"/></a>
24-
<% end %>
10+
{{ if isset .Params.book "ebook_pdf" }}
11+
<a href="{{ .Params.book.ebook_pdf }}"><img width="50px" src="{{ relURL "images/pdf.png" }}"/></a>
12+
{{ end }}
13+
{{ if .Params.book.ebook_epub }}
14+
<a href="{{ .Params.book.ebook_epub }}"><img width="50px" src="{{ relURL "images/epub.png" }}"/></a>
15+
{{ end }}
2516
</div>
2617
<div class="ebooks">
27-
<% if @book.ebook_mobi %>
28-
<a href="<%= @book.ebook_mobi %>"><img width="50px" src="{{ relURL "images/mobi.png" }}"/></a>
29-
<% end %>
18+
{{ if .Params.book.ebook_mobi }}
19+
<a href="{{ .Params.book.ebook_mobi }}"><img width="50px" src="{{ relURL "images/mobi.png" }}"/></a>
20+
{{ end }}
3021
</div>
3122
</div>
32-
<% end %>
23+
{{ end }}
3324
</div>
34-
<% else %>
35-
<div class="book-wrapper">
36-
<img src="{{ relURL "images/books/[email protected]" }}" width="118" height="157"/>
37-
<div>1st Edition (2009)</div>
38-
<% if @book.edition?(2) %>
39-
<div class="switch"><a href="{{ relURL "book/<%= @book.code %>/v2" }}">Switch to 2nd Edition</a></div>
40-
<% end %>
41-
</div>
42-
<% end %>
4325
<p>
4426
The entire Pro Git book, written by Scott Chacon and Ben Straub and published by Apress, is available here. All content is licensed under the <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution Non Commercial Share Alike 3.0 license</a>. Print versions of the book are available on <a href="https://www.amazon.com/Pro-Git-Scott-Chacon/dp/1484200772?ie=UTF8&camp=1789&creative=9325&creativeASIN=1430218339&linkCode=as2&tag=git-sfconservancy-20">Amazon.com</a>.
4527
</p>
@@ -48,21 +30,23 @@ <h2>Download Ebook</h2>
4830
</p>
4931

5032
<ol class='book-toc'>
51-
<% @book.chapters.includes(:sections).each do |chapter| %>
52-
<% next if chapter.sections.size == 0 %>
33+
{{ range (index (.Scratch.Get "book") "chapters") }}
34+
{{ $section_count := .sections | len }}
35+
{{ if (ne $section_count 0) }}
5336
<li class='chapter'>
54-
<h2><%= chapter.cs_number %>. <a href="{{ relURL "book/<%= @book.code %>/v<%= @book.edition %>/<%=u chapter.sections.first.slug %>" }}"><%= chapter.title %></a></h2>
37+
<h2>{{ .cs_number }}. <a href="{{ relURL (replace (index (index .sections 0) "url") "?" "%3F") }}">{{ .title }}</a></h2>
5538
<ol>
56-
<% chapter.sections.each do |section| %>
57-
<% if !section.title.empty? %>
39+
{{ range .sections }}
40+
{{ if (ne .title "") }}
5841
<li>
59-
<%= chapter.cs_number %>.<%= section.number %>
60-
<a href="{{ relURL "book/<%= @book.code %>/v<%= @book.edition %>/<%= u(section.slug) %>" }}"><%=raw section.title %></a>
42+
{{ .cs_number }}
43+
<a href="{{ relURL (replace .url "?" "%3F") }}">{{ .title }}</a>
6144
</li>
62-
<% end %>
63-
<% end %>
45+
{{ end }}
46+
{{ end }}
6447
</ol>
6548
</li>
66-
<% end %>
49+
{{ end }}
50+
{{ end }}
6751
</ol>
6852
</div>
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
<ol class='book-toc'>
2-
<% per_column = (@book.chapters.count / 3.0).ceil -%>
3-
<% start = per_column * (column - 1) -%>
4-
<% stop = start + (per_column - 1) -%>
5-
<% @book.chapters.includes(:sections)[start..stop].each do |chapter| %>
6-
<% if chapter %>
7-
<% if chapter.sections.size > 0 %>
2+
{{ range $i, $chapter := index (.Scratch.Get "book") "chapters" }}
3+
{{ if (and (ge $i ($.Scratch.Get "first_chapter")) (le $i ($.Scratch.Get "last_chapter"))) }}
84
<li class='chapter'>
9-
<h2><%= chapter.cs_number %>. <a href="{{ relURL "book/<%= @book.code %>/v<%= @book.edition %>/<%=u chapter.sections.first.slug %>" }}"><%=raw chapter.title %></a></h2>
5+
<h2>{{ $chapter.cs_number }}. <a href="{{ relURL (replace (index (index $chapter.sections 0) "url") "?" "%3F") }}">{{ $chapter.title }}</a></h2>
106
<ol>
11-
<% chapter.sections.each do |section| %>
12-
<% unless section.title.empty? %>
7+
{{ range $section := $chapter.sections }}
138
<li>
14-
<%= chapter.cs_number %>.<%= section.number %>
15-
<a href="{{ relURL "book/<%= @book.code %>/v<%= @book.edition %>/<%= u(section.slug) %>" }}" <%= 'class=active' if same_section(@content, section) %>><%= raw section.title %> </a>
9+
{{ $section.cs_number }}
10+
<a href="{{ relURL (replace $section.url "?" "%3F") }}"{{ if (eq $section.cs_number $.Params.book.section.cs_number) }} class="active"{{ end }}>{{ $section.title }}</a>
1611
</li>
17-
<% end %>
18-
<% end %>
12+
{{ end }}
1913
</ol>
2014
</li>
21-
<% end %>
22-
<% end %>
23-
<% end %>
15+
{{ end }}
16+
{{ end }}
2417
</ol>

layouts/partials/chapters.html

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
<a class="dropdown-trigger" id="book-chapters-trigger" data-panel-id="chapters-dropdown" href="#">Chapters ▾</a>
2+
{{ $chapter_count := len (index (.Scratch.Get "book") "chapters") }}
3+
{{ $first_chapter_left_column := 0 }}
4+
{{ $last_chapter_left_column := math.Floor (div $chapter_count 3.0) }}
5+
{{ $first_chapter_middle_column := add $last_chapter_left_column 1 }}
6+
{{ $last_chapter_middle_column := math.Ceil (div $chapter_count 1.5) }}
7+
{{ $first_chapter_right_column := add $last_chapter_middle_column 1 }}
8+
{{ $last_chapter_right_column := $chapter_count }}
29
<div class='dropdown-panel' id='chapters-dropdown'>
3-
<div class="three-column">
4-
<div class='column-left'>
5-
<%= render :partial => 'chapter_listings', :locals => {:column => 1} %>
10+
<div class='three-column'>
11+
<div class="column-left">
12+
{{ .Scratch.Set "first_chapter" $first_chapter_left_column }}
13+
{{ .Scratch.Set "last_chapter" $last_chapter_left_column }}
14+
{{ partial "chapter_listings.html" . }}
615
</div>
716
<div class='column-middle'>
8-
<%= render :partial => 'chapter_listings', :locals => {:column => 2} %>
17+
{{ .Scratch.Set "first_chapter" $first_chapter_middle_column }}
18+
{{ .Scratch.Set "last_chapter" $last_chapter_middle_column }}
19+
{{ partial "chapter_listings.html" . }}
920
</div>
1021
<div class='column-right'>
11-
<%= render :partial => 'chapter_listings', :locals => {:column => 3} %>
22+
{{ .Scratch.Set "first_chapter" $first_chapter_right_column }}
23+
{{ .Scratch.Set "last_chapter" $last_chapter_right_column }}
24+
{{ partial "chapter_listings.html" . }}
1225
</div>
1326
</div>
14-
</div>
27+
</div>

0 commit comments

Comments
 (0)