summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2015-11-01 21:16:42 -0500
committerluxagraf <sng@luxagraf.net>2015-11-01 21:16:42 -0500
commit47ab118686d3216598b57188a67c81f9cf169c50 (patch)
treedf1deec3a59d13115bb4b09c042345c0354b68dd
parente8d1fa3f47f8520618bd83dd917c569c83f2de86 (diff)
added epub script basics and styled figments archives and details
-rw-r--r--app/figments/build.py15
-rw-r--r--app/figments/ebook.py79
-rw-r--r--design/sass/_figments.scss32
-rw-r--r--design/templates/archives/figments.html27
-rw-r--r--design/templates/details/figments.html5
5 files changed, 144 insertions, 14 deletions
diff --git a/app/figments/build.py b/app/figments/build.py
index b0890fd..58835e5 100644
--- a/app/figments/build.py
+++ b/app/figments/build.py
@@ -2,11 +2,12 @@ from builder.base import *
from .models import Figment, Series
-class BuildSrc(Build):
+class BuildFigments(Build):
def build(self):
self.build_archive()
self.build_topic_archive()
self.build_detail_pages()
+ self.build_detail_epub()
self.build_feed()
def build_detail_pages(self):
@@ -21,6 +22,18 @@ class BuildSrc(Build):
s = render_to_string('details/note.txt', c).encode('utf-8')
self.write_file(path, s, 'txt', entry.slug)
+ def build_detail_epub(self):
+ '''
+ Grab all the notes, render them to a template string and write that out to the filesystem
+ '''
+ for entry in Figment.objects.filter(status__exact=1):
+ c = Context({'object': entry, 'MEDIA_URL': settings.BAKED_MEDIA_URL, 'IMAGES_URL': settings.BAKED_IMAGES_URL, 'SITE_URL':settings.SITE_URL})
+ t = render_to_string('details/fignments.html', c).encode('utf-8')
+ path = 'figments/'
+ self.write_file(path, t, 'html', entry.slug)
+ s = render_to_string('details/note.txt', c).encode('utf-8')
+ self.write_file(path, s, 'txt', entry.slug)
+
def build_archive(self):
path = 'figments/'
c = Context({
diff --git a/app/figments/ebook.py b/app/figments/ebook.py
new file mode 100644
index 0000000..23e3fc5
--- /dev/null
+++ b/app/figments/ebook.py
@@ -0,0 +1,79 @@
+import os
+from ebooklib import epub
+
+from django.conf import settings
+from typogrify.filters import typogrify
+
+def generate_epub_file(f):
+ book = epub.EpubBook()
+
+ # add metadata
+ book.set_identifier('lux23')
+ book.set_title(f.title)
+ book.set_language('en')
+
+ book.add_author('Scott Gilbertson')
+
+ # intro chapter
+ c1 = epub.EpubHtml(title='Introduction', file_name='intro.xhtml', lang='en')
+ c1.content=u'<html><head></head><body><h1>Forward</h1><p>Thank you for downloading my story <em>%s</em>. I hope you enjoy it and please feel free to email me if you have any questions or comments.</p> <p>If you enjoy this story and would like to read more, head on over to <a href="http://luxagraf.net/figments/">luxagraf.net</a>.</p><p>&ndash; Scott Gilbertson <br/> &nbsp;&nbsp;sng@luxagraf.net</p></body></html>' % f.title
+
+ # chapter
+ c2 = epub.EpubHtml(title=f.title, file_name='story.xhtml')
+ c2.content='<h1>%s</h1>' % f.title
+ c2.content+= typogrify(f.body_html)
+
+ # add chapters to the book
+ book.add_item(c1)
+ book.add_item(c2)
+
+ # create table of contents
+ # - add section
+ # - add auto created links to chapters
+
+ book.toc = (epub.Link('intro.xhtml', 'Introduction', 'intro'),
+ epub.Link('story.xhtml', f.title, 'story'),
+ )
+
+ # add navigation files
+ book.add_item(epub.EpubNcx())
+ book.add_item(epub.EpubNav())
+
+ # define css style
+ style = '''
+@namespace epub "http://www.idpf.org/2007/ops";
+body {
+ font-family: Georgia, Times, Times New Roman, serif;
+}
+h2 {
+ text-align: left;
+ text-transform: uppercase;
+ font-weight: 200;
+}
+ol {
+ list-style-type: none;
+}
+ol > li:first-child {
+ margin-top: 0.3em;
+}
+nav[epub|type~='toc'] > ol > li > ol {
+ list-style-type:square;
+}
+nav[epub|type~='toc'] > ol > li > ol > li {
+ margin-top: 0.3em;
+}
+'''
+
+ # add css file
+ nav_css = epub.EpubItem(uid="style_nav", file_name="style/nav.css", media_type="text/css", content=style)
+ book.add_item(nav_css)
+
+ # create spine
+ book.spine = ['nav', c1, c2]
+ path, filename = os.path.split(f.get_absolute_url())
+ fpath = '%s%s/' %(settings.FLATFILES_ROOT, path)
+ if not os.path.isdir(fpath):
+ os.makedirs(fpath)
+ bk = '%s%s.epub' %(fpath, f.slug)
+ # create epub file
+ epub.write_epub(bk, book, {})
diff --git a/design/sass/_figments.scss b/design/sass/_figments.scss
index cc4d7f5..1204743 100644
--- a/design/sass/_figments.scss
+++ b/design/sass/_figments.scss
@@ -1,4 +1,34 @@
-.kindle {
+.kindle, .epub {
+ display: inline;
@include smcaps;
@include fontsize(11);
}
+.kindle:after {
+ content: "ยท";
+ color: #999;
+ padding-left: 0.75em;
+}
+.fig-archive {
+ @include constrain_narrow;
+ @include breakpoint(beta) {
+ text-align: left;
+
+ }
+ h1 {
+ margin-top: 2.5em;
+ @include smcaps;
+ @include fontsize(16);
+ }
+ p:first-of-type {
+ margin-bottom: 4em;
+ @include breakpoint(beta) {
+ text-align: left;
+ @include fontsize(18);
+ font-style: italic
+ }
+ }
+ h2 {
+ @include smcaps;
+ @include fontsize(18);
+ }
+}
diff --git a/design/templates/archives/figments.html b/design/templates/archives/figments.html
index 5c5e398..8b5c78e 100644
--- a/design/templates/archives/figments.html
+++ b/design/templates/archives/figments.html
@@ -1,18 +1,23 @@
{% extends 'base.html' %}
{% load typogrify_tags %}
-{% block primary %}
- <main role="main">
+{% block primary %}<ul class="bl" id="breadcrumbs" itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
+ <li><a href="/" title="luxagraf homepage" itemprop="url"><span itemprop="title">Home</span></a> &rarr; </li>{% if series %}
+ <li><a href="/figments/" title="Figments" itemprop="url"><span itemprop="title">Figments</span></a> &rarr; </li>
+ <li>{{topic}}</li>{%else%}
+ <li>Figments</li>{%endif%}
+ </ul>
+ <main role="main" id="figments-archive" class="fig-archive">
+ <h1>Figments of Imagination</h1>
+ <p>I dislike the term &#8220;fiction&#8221; because it implies that there is a non-fiction and I categorically deny that such a thing can exist. So I call these stories &#8220;less true stories mostly made up&#8221; and hope for the best, where &#8220;the best&#8221; is that you enjoy them.</p>
+
{% for object in object_list %}
- <article class="h-entry hentry post--article{% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %} post--article--double{%endif%}{%endwith%}" itemscope itemType="http://schema.org/Article">
- <header id="header" class="post--header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}">
- <h1 class="p-name entry-title post--title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|widont|safe}}{%endif%}</h1>
- <p class="p-author author hide" itemprop="author"><span class="byline-author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Scott Gilbertson</span></span></p>
- </header>
- <div id="article" class="e-content entry-content post--body post--body--{% with object.template_name as t %}{%if t == 0 or t == 2 %}single{%endif%}{%if t == 1 or t == 3 %}double{%endif%}{%endwith%}" itemprop="articleBody">
- {{object.title|safe|smartypants|widont}}
- </div>
- </article>
+ <article id="{{object.slug}}{{object.pk}}" class="h-entry hentry figment" itemscope itemType="http://schema.org/CreativeWork">
+ <h2 class="p-name entry-title post--title" itemprop="headline"><a href="{{object.get_absolute_url}}" class="u-url permalink">{{object.title|smartypants|safe}}</a></h2>
+ <p class="p-author author hide" itemprop="author"><span class="byline-author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Scott Gilbertson</span></span></p>
+ <p class="hide p-category">Fiction</p>
+ <p class="p-summary entry-summary">{{object.dek|safe|smartypants|widont}} <a href="{{object.get_absolute_url}}">Read&nbsp;&#8674;</a></p>
+ </article>
{%endfor%}
</main>
{% endblock %}
diff --git a/design/templates/details/figments.html b/design/templates/details/figments.html
index 3aeb690..1f8bfc7 100644
--- a/design/templates/details/figments.html
+++ b/design/templates/details/figments.html
@@ -7,7 +7,10 @@
<header id="header" class="post--header {% with object.get_template_name_display as t %}{%if t == "double" or t == "double-dark" %}post--header--double{%endif%}{%endwith%}">
<h1 class="p-name entry-title post--title" itemprop="headline">{%if object.template_name == 1 or object.template_name == 3 %}{{object.title|smartypants|safe}}{%else%}{{object.title|smartypants|widont|safe}}{%endif%}</h1>
<time class="hide dt-published published dt-updated post--date" datetime="{{object.pub_date|date:'c'}}" itemprop="datePublished">{{object.pub_date|date:"F"}} <span>{{object.pub_date|date:"j, Y"}}</span></time>
- <p class="kindle"><a href="">Send to Kindle</a></p>
+ <ul>
+ <li class="kindle"><a href="">Send to Kindle</a></li>
+ <li class="epub"><a href="{{object.get_absolute_url}}.epub">Download for iBooks (epub)</a></li>
+ </ul>
<p class="p-author author hide" itemprop="author"><span class="byline-author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Scott Gilbertson</span></span></p>
</header>
<div id="article" class="e-content entry-content post--body post--body--{% with object.template_name as t %}{%if t == 0 or t == 2 %}single{%endif%}{%if t == 1 or t == 3 %}double{%endif%}{%endwith%}" itemprop="articleBody">