Skip to content

Commit ac8eee3

Browse files
author
Tom Clark
committed
Added rake task to generate a table of contents page
1 parent c4dd1dc commit ac8eee3

File tree

8 files changed

+84
-6
lines changed

8 files changed

+84
-6
lines changed

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source :rubygems
2+
3+
gem 'fileutils'
4+
gem 'jekyll'
5+
gem 'tempfile'

Gemfile.lock

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
albino (1.3.3)
5+
posix-spawn (>= 0.3.6)
6+
classifier (1.3.3)
7+
fast-stemmer (>= 1.0.0)
8+
directory_watcher (1.4.1)
9+
fast-stemmer (1.0.1)
10+
fileutils (0.7)
11+
rmagick (>= 2.13.1)
12+
jekyll (0.11.2)
13+
albino (~> 1.3)
14+
classifier (~> 1.3)
15+
directory_watcher (~> 1.1)
16+
kramdown (~> 0.13)
17+
liquid (~> 2.3)
18+
maruku (~> 0.5)
19+
kramdown (0.13.7)
20+
liquid (2.3.0)
21+
maruku (0.6.0)
22+
syntax (>= 1.0.0)
23+
posix-spawn (0.3.6)
24+
rmagick (2.13.1)
25+
syntax (1.0.0)
26+
27+
PLATFORMS
28+
ruby
29+
30+
DEPENDENCIES
31+
fileutils
32+
jekyll

Rakefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'rubygems'
2+
require 'rake'
3+
4+
task :default => :update_toc
5+
6+
desc "Regenerate the table of contents to include links to newest tutorials"
7+
task :update_toc do
8+
require 'jekyll'
9+
require 'tempfile'
10+
require 'fileutils'
11+
12+
site = Jekyll::Site.new(Jekyll.configuration({})) and site.read
13+
14+
pages = site.pages.reject {|p| p.data["ignore"] }.reverse
15+
16+
toc_path = File.join(FileUtils.pwd, "pages", "table_of_contents.md")
17+
temp = Tempfile.new("table_of_contents.md")
18+
19+
begin
20+
File.readlines(toc_path).each do |line|
21+
line =~ /^<!--- BEGIN TOC -->$/ ? break : temp.puts(line)
22+
end
23+
temp.puts "<!--- BEGIN TOC -->"
24+
pages.each_with_index do |page, index|
25+
temp.puts " * [#{page.data["title"]}](#{page.destination('')})"
26+
end
27+
temp.puts "<!--- END TOC -->"
28+
FileUtils.mv(temp.path, toc_path)
29+
ensure
30+
temp.delete
31+
end
32+
end

foo.md

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

index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: default
33
title: Decentralized Polyglot Tutorials
4+
ignore: true
45
---
56

67
README

pages/another_test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: default
33
title: Test
4+
ignore: true
45
---
56

67
Hello, World!

pages/table_of_contents.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
layout: default
3+
title: Table of Contents
4+
ignore: true
5+
---
6+
7+
This is the TOC. It should not be edited
8+
9+
<!--- BEGIN TOC -->
10+
* [Installing MySQL](/pages/installing-mysql.html)
11+
* [Hello, World!](/pages/hello-world.html)
12+
<!--- END TOC -->

pages/test.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: default
33
title: Test
4+
ignore: true
45
---
56

67
Javascript Testing

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy