Skip to content

Commit

Permalink
Enable custom book
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Aug 5, 2015
1 parent 770e167 commit 25703d3
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 118 deletions.
20 changes: 20 additions & 0 deletions _books/99-custom-1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
layout: custom-book
book: 99
title: My Custom Book
habits-color: rgb(0, 179, 208)
lessons:
- book: 7
lesson: 0
- book: 10
lesson: 0
- book: 7
lesson: 1
order: 1
- book: 7
lesson: 2
order: 2
- book: 10
lesson: 1
order: 3
---
120 changes: 120 additions & 0 deletions _includes/book.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!DOCTYPE html>

{% assign lessons = include.lessons %}
{% assign summary = include.summary %}
{% assign answers = include.answers %}

<html lang='en'>

{% include head.html %}

<body class="book-page">

{% include header.html %}

<section class="book book-{{page.book}}">

<section class="info"></section>

<section class="container title-page">
<h1>Book {{page.book}}: {{ page.title }}</h1>
</section>

<section class="container toc">
<h1>Table of Contents</h1>
<ul class="lessons">
<li>
<a href="#habits-of-mind">
Mathematical Habits of Mind
</a>
</li>
{% for lesson in lessons %}
{% assign content = (site.lessons | where: 'book', lesson.book | where: 'lesson', lesson.lesson | first %}
{% if content.published and lesson.lesson %}
<li>
<a href="#{{lesson.lesson}}-{{content.title | slugify}}">
{% include lesson-title.html lesson=lesson content=content %}
</a>
</li>
{% endif %}
{% endfor %}
{% if summary.published %}
<li>
<a href="#summary-and-review">Summary and Review</a>
</li>
{% endif %}

{% if answers.published %}
<li>
<a href="#answers">Selected Answers</a>
</li>
{% endif %}
</ul>
</section>



<section class="habit-list" id="habits-of-mind">
{% include habit-header.html %}
<div class="container">
<dl>
{% for habit in site.data.habits %}
<dt>{{habit.name}}</dt>
<dd>{{habit.definition}}</dd>
{% endfor %}
</dl>
</div>
</section>


{% for lesson in lessons %}
{% assign content = (site.lessons | where: 'book', lesson.book | where: 'lesson', lesson.lesson | first %}
{% if content.published and lesson.lesson %}
{% assign habits = (site.data.habits | where: 'name', content.title) %}
{% unless habits == empty %}
{% assign habit = habits[0] %}
{% assign habitclass = 'habit-lesson' %}
{% else %}
{% assign habit = false %}
{% assign habitclass = '' %}
{% endunless %}

<section class="lesson {{habitclass}}" id="{{lesson.lesson}}-{{content.title | slugify}}">
{% if habit %}
{% include habit-header.html habit=habit %}
{% endif %}
<div class="container">
<h1>{% include lesson-title.html lesson=lesson content=content %}</h1>
{% capture emptytag %}{% raw %}{% %}{% endraw %}{% endcapture %}
{{ content.content | remove_first: 'raw' | remove: 'endraw' | remove: emptytag }}
</div>
</section>
{% endif %}
{% endfor %}

{% if summary.published %}
<section class="lesson" id="summary-and-review">
<div class="container">
{% capture emptytag %}{% raw %}{% %}{% endraw %}{% endcapture %}
{{ summary.content | remove_first: 'raw' | remove: 'endraw' | remove: emptytag }}
</div>
</section>
{% endif %}

{% if answers.published %}
<section class="answers" id="answers">
<div class="container">
{% capture emptytag %}{% raw %}{% %}{% endraw %}{% endcapture %}
{{ answers.content | remove_first: 'raw' | remove: 'endraw' | remove: emptytag }}
</div>
</section>
{% endif %}

</section>

{% include footer.html %}

</body>

</html>

11 changes: 8 additions & 3 deletions _includes/lesson-title.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{% if lesson.type == 'habit' %}
{% if include.lesson.order %}
{% assign lessonNumber = include.lesson.order %}
{% else %}
{% assign lessonNumber = include.content.lesson %}
{% endif %}
{% if include.content.type == 'habit' %}
Habits of Mind:
{% else %}
Lesson {{ lesson.lesson }}:
Lesson {{ lessonNumber }}:
{% endif %}
{% assign words = (lesson.title | prepend: '' | split: ' ') %}
{% assign words = (include.content.title | prepend: '' | split: ' ') %}
{% for word in words %}{{ word | capitalize }} {% endfor %}
119 changes: 4 additions & 115 deletions _layouts/book.html
Original file line number Diff line number Diff line change
@@ -1,116 +1,5 @@
<!DOCTYPE html>
<html lang='en'>

{% include head.html %}

<body class="book-page">

{% include header.html %}

{% assign lessons = (site.lessons | where: 'book', page.book) %}
{% assign summary = lessons | where: 'type', 'summary' | first %}
{% assign answers = lessons | where: 'type', 'answers' | first %}

<section class="book book-{{page.book}}">

<section class="info"></section>

<section class="container title-page">
<h1>Book {{page.book}}: {{ page.title }}</h1>
</section>

<section class="container toc">
<h1>Table of Contents</h1>
<ul class="lessons">
<li>
<a href="#habits-of-mind">
Mathematical Habits of Mind
</a>
</li>
{% for lesson in lessons %}
{% if lesson.published and lesson.lesson %}
<li>
<a href="#lesson-{{ page.book }}-{{ lesson.lesson }}">
{% include lesson-title.html lesson=lesson %}
</a>
</li>
{% endif %}
{% endfor %}
{% if summary.published %}
<li>
<a href="#summary-and-review">Summary and Review</a>
</li>
{% endif %}

{% if answers.published %}
<li>
<a href="#answers">Selected Answers</a>
</li>
{% endif %}
</ul>
</section>



<section class="habit-list" id="habits-of-mind">
{% include habit-header.html %}
<div class="container">
<dl>
{% for habit in site.data.habits %}
<dt>{{habit.name}}</dt>
<dd>{{habit.definition}}</dd>
{% endfor %}
</dl>
</div>
</section>


{% for lesson in lessons %}
{% if lesson.published and lesson.lesson %}
{% assign habits = (site.data.habits | where: 'name', lesson.title) %}
{% unless habits == empty %}
{% assign habit = habits[0] %}
{% assign habitclass = 'habit-lesson' %}
{% else %}
{% assign habit = false %}
{% assign habitclass = '' %}
{% endunless %}

<section class="lesson {{habitclass}}" id="lesson-{{ page.book }}-{{ lesson.lesson }}">
{% if habit %}
{% include habit-header.html habit=habit %}
{% endif %}
<div class="container">
{% capture emptytag %}{% raw %}{% %}{% endraw %}{% endcapture %}
{{ lesson.content | remove_first: 'raw' | remove: 'endraw' | remove: emptytag }}
</div>
</section>
{% endif %}
{% endfor %}

{% if summary.published %}
<section class="lesson" id="summary-and-review">
<div class="container">
{% capture emptytag %}{% raw %}{% %}{% endraw %}{% endcapture %}
{{ summary.content | remove_first: 'raw' | remove: 'endraw' | remove: emptytag }}
</div>
</section>
{% endif %}

{% if answers.published %}
<section class="answers" id="answers">
<div class="container">
{% capture emptytag %}{% raw %}{% %}{% endraw %}{% endcapture %}
{{ answers.content | remove_first: 'raw' | remove: 'endraw' | remove: emptytag }}
</div>
</section>
{% endif %}

</section>

{% include footer.html %}

</body>

</html>
{% assign lessons = (site.lessons | where: 'book', page.book) %}
{% assign summary = lessons | where: 'type', 'summary' | first %}
{% assign answers = lessons | where: 'type', 'answers' | first %}

{% include book.html lessons=lessons summary=summary answers=answers %}
1 change: 1 addition & 0 deletions _layouts/custom-book.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include book.html lessons=page.lessons summary=page.summary answers=page.answers %}
15 changes: 15 additions & 0 deletions books/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
layout: default
---
<div class="home">
<ul class="toc">
{% for book in site.books %}
<li class="book">
Book {{ book.book }}: {{ book.title }}
<a href="{{ book.url | prepend: site.baseurl }}">[HTML]</a>
{% assign pdf = book.path | split: "/" | last | split: '.' | first | append: '.pdf' | prepend: '/pdf/' | prepend: site.baseurl %}
<a href="{{ pdf }}">[PDF]</a>
</li>
{% endfor %}
</ul>
</div>

0 comments on commit 25703d3

Please sign in to comment.