Skip to content

Commit 7abb9ca

Browse files
committed
Add support for collection
GitHub: fix GH-8 Reported by Jeremy Lloyd Conlin. Thanks!!!
1 parent 22bb99d commit 7abb9ca

File tree

6 files changed

+101
-13
lines changed

6 files changed

+101
-13
lines changed

example/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ source "https://rubygems.org/"
1616

1717
gem "jekyll"
1818
gem "jekyll-jupyter-notebook", path: ".."
19+
gem "webrick"

example/_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ exclude:
1616
- "Gemfile.lock"
1717
plugins:
1818
- jekyll-jupyter-notebook
19+
collections:
20+
members:
21+
output: true
22+
permalink: /members/:path

example/_members/alice.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
layout: default
3+
name: alice
4+
title: Alice
5+
---
6+
7+
## Title
8+
9+
{% jupyter_notebook "python-alice.ipynb" %}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [
10+
{
11+
"data": {
12+
"text/plain": [
13+
"sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)"
14+
]
15+
},
16+
"execution_count": 1,
17+
"metadata": {},
18+
"output_type": "execute_result"
19+
}
20+
],
21+
"source": [
22+
"import sys\n",
23+
"sys.version_info"
24+
]
25+
}
26+
],
27+
"metadata": {
28+
"kernelspec": {
29+
"display_name": "Python 3",
30+
"language": "python",
31+
"name": "python3"
32+
},
33+
"language_info": {
34+
"codemirror_mode": {
35+
"name": "ipython",
36+
"version": 3
37+
},
38+
"file_extension": ".py",
39+
"mimetype": "text/x-python",
40+
"name": "python",
41+
"nbconvert_exporter": "python",
42+
"pygments_lexer": "ipython3",
43+
"version": "3.5.2"
44+
}
45+
},
46+
"nbformat": 4,
47+
"nbformat_minor": 2
48+
}

example/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ Here is a Jupyter Notebook:
2222
{% for post in site.posts %}
2323
* [{{ post.title }} ({{ post.date | date: "%Y-%m-%d" }})]({{ post.url }})
2424
{% endfor %}
25+
26+
### Collection: members
27+
28+
* [Alice]({% link _members/alice.md %})

lib/jekyll-jupyter-notebook/generator.rb

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,48 @@
1111
# limitations under the License.
1212

1313
module JekyllJupyterNotebook
14-
module IFramePage
14+
module IFramable
1515
def output_ext
16-
ext + super
16+
extname + super
1717
end
1818
end
1919

2020
class Generator < Jekyll::Generator
2121
def generate(site)
22+
generate_site_static_files(site)
23+
site.collections.each_value do |collection|
24+
generate_collection_filtered_entries(collection)
25+
end
26+
end
27+
28+
private
29+
def generate_site_static_files(site)
2230
site.static_files.reject! do |static_file|
23-
if static_file.extname == ".ipynb"
24-
base = static_file.instance_variable_get(:@base)
25-
dir = static_file.instance_variable_get(:@dir)
26-
name = static_file.name
27-
page = Jekyll::Page.new(site, base, dir, name)
28-
page.extend(IFramePage)
29-
site.pages << page
30-
true
31-
else
32-
false
33-
end
31+
next false unless static_file.extname == ".ipynb"
32+
33+
base = static_file.instance_variable_get(:@base)
34+
dir = static_file.instance_variable_get(:@dir)
35+
name = static_file.name
36+
page = Jekyll::Page.new(site, base, dir, name)
37+
page.extend(IFramable)
38+
site.pages << page
39+
true
40+
end
41+
end
42+
43+
def generate_collection_filtered_entries(collection)
44+
collection.filtered_entries.reject! do |file_path|
45+
full_path = collection.collection_dir(file_path)
46+
next false unless File.extname(file_path) == ".ipynb"
47+
next false if Jekyll::Utils.has_yaml_header?(full_path)
48+
49+
document = Jekyll::Document.new(full_path,
50+
site: collection.site,
51+
collection: collection)
52+
document.extend(IFramable)
53+
document.read
54+
collection.docs << document
55+
true
3456
end
3557
end
3658
end

0 commit comments

Comments
 (0)