Initial commit of entire workspace
This includes a workable Makefile, able to generate readable ePub documents for all existing content.
This commit is contained in:
commit
76b963bc35
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Ignore output directories.
|
||||||
|
build/
|
||||||
|
tmp/
|
19
LICENSE
Normal file
19
LICENSE
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Copyright (c) 2023 Alex Palaistras
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
96
Makefile
Normal file
96
Makefile
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
# Makefile for Plato - The Stanford Encyclopedia of Philosophy, in ePub
|
||||||
|
# Use this to build a new version of the ePub document from remote sources.
|
||||||
|
|
||||||
|
# Document generation options.
|
||||||
|
NAME := Stanford Encyclopedia of Philosophy
|
||||||
|
BASE_URL := https://plato.stanford.edu
|
||||||
|
|
||||||
|
# Build-time dependencies.
|
||||||
|
AWK = $(call find-cmd,awk)
|
||||||
|
GREP = $(call find-cmd,grep)
|
||||||
|
PANDOC = $(call find-cmd,pandoc) $(if $(VERBOSE),--verbose)
|
||||||
|
WGET = $(call find-cmd,wget) $(if $(VERBOSE),,--quiet)
|
||||||
|
KEPUBIFY = $(call find-cmd,kepubify) $(if $(VERBOSE),--verbose)
|
||||||
|
|
||||||
|
# Directory aliases.
|
||||||
|
ROOTDIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||||
|
BUILDDIR := $(ROOTDIR)build/
|
||||||
|
TMPDIR := $(ROOTDIR)tmp/
|
||||||
|
|
||||||
|
# Default Makefile options.
|
||||||
|
VERBOSE :=
|
||||||
|
ENABLE_KOBO :=
|
||||||
|
|
||||||
|
## Build ePub documents via Pandoc.
|
||||||
|
build: $(addprefix $(BUILDDIR),$(addsuffix $(if $(ENABLE_KOBO),.kepub).epub,$(basename $(notdir $(wildcard $(TMPDIR)entries/*.md)))))
|
||||||
|
|
||||||
|
## Remove all temporary files.
|
||||||
|
clean:
|
||||||
|
$Q rm --recursive --force $(if $(VERBOSE),--verbose) $(TMPDIR)
|
||||||
|
|
||||||
|
## Remove all temporary and build files.
|
||||||
|
purge:
|
||||||
|
$Q rm --recursive --force $(if $(VERBOSE),--verbose) $(BUILDDIR) $(TMPDIR)
|
||||||
|
|
||||||
|
$(BUILDDIR)%.kepub.epub: $(BUILDDIR)%.epub
|
||||||
|
$Q $(KEPUBIFY) --inplace --smarten-punctuation --output $@ $<
|
||||||
|
|
||||||
|
$(BUILDDIR)%.epub: $(TMPDIR)entries/%.md
|
||||||
|
$Q install -d $(@D)
|
||||||
|
$Q cd $(TMPDIR)entries/$* && $(PANDOC) --from markdown --to epub --mathml $< > $@
|
||||||
|
|
||||||
|
$(TMPDIR)entries/%.md: $(TMPDIR)entries/%/index.html
|
||||||
|
$Q install -d $(@D)
|
||||||
|
$Q $(AWK) "$$EXTRACT_ARTICLE_META" $< > $@
|
||||||
|
$Q $(PANDOC) --from html+tex_math_single_backslash+tex_math_double_backslash --to markdown $< | $(AWK) "$$EXTRACT_ARTICLE" >> $@
|
||||||
|
|
||||||
|
$(TMPDIR)%.html:
|
||||||
|
$Q install -d $(@D)
|
||||||
|
$Q $(WGET) --no-clobber --page-requisites --accept html,png,jpg,jpeg,gif,svg --no-directories --directory-prefix $(@D) $(BASE_URL)/$*.html
|
||||||
|
|
||||||
|
$(TMPDIR)table-of-contents.md: $(TMPDIR)contents.html
|
||||||
|
$Q install -d $(@D)
|
||||||
|
$Q $(PANDOC) --from html --to markdown $< | $(AWK) "$$EXTRACT_TOC" > $@
|
||||||
|
|
||||||
|
.PHONY: build clean purge
|
||||||
|
|
||||||
|
$(TMPDIR)make.depend: $(TMPDIR)table-of-contents.md
|
||||||
|
@printf "build: $<" > $@
|
||||||
|
@for i in `$(GREP) -Po '\[.+?\]\(\Kentries/[^/]+' $<`; do printf " $(TMPDIR)$${i}.md"; done >> $@
|
||||||
|
|
||||||
|
# Conditional command echo control.
|
||||||
|
Q := $(if $(VERBOSE),,@)
|
||||||
|
|
||||||
|
# Find and return full path to command by name, or throw error if none can be found in PATH.
|
||||||
|
# Example use: $(call find-cmd,ls)
|
||||||
|
find-cmd = $(or $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))),$(error "Command '$(1)' not found in PATH"))
|
||||||
|
|
||||||
|
# Awk script for extracting bare table-of-contents body from Markdown source.
|
||||||
|
define EXTRACT_TOC
|
||||||
|
$$0 ~ "::: {#toc-wrapper}" {s=1; next}
|
||||||
|
$$0 ~ "Projected Table of Contents" {s=0}
|
||||||
|
$$1 != ":::" && s == 1 {print}
|
||||||
|
endef
|
||||||
|
export EXTRACT_TOC
|
||||||
|
|
||||||
|
# Awk script for extracting article metadata from HTML source.
|
||||||
|
define EXTRACT_ARTICLE_META
|
||||||
|
BEGIN {FS="\""; print "---"}
|
||||||
|
$$2 == "citation_title" {printf "title: \"%s\"\n", $$4; next}
|
||||||
|
$$2 == "citation_author" {if (c==0) {print "creator:"; c=1}; printf "- role: author\n text: \"%s\"\n", $$4; next}
|
||||||
|
END {print "publisher: \"$(NAME)\""; print "belongs-to-collection: \"$(NAME)\""; print "---"}
|
||||||
|
endef
|
||||||
|
export EXTRACT_ARTICLE_META
|
||||||
|
|
||||||
|
# Awk script for extracting bare aricle body from Markdown source.
|
||||||
|
define EXTRACT_ARTICLE
|
||||||
|
$$0 ~ "::: {#article-content}" {s=1; next}
|
||||||
|
$$0 ~ "::: {#toc}" {s=0; next}
|
||||||
|
$$0 ~ "::: {#main-text}" {s=1; next}
|
||||||
|
$$0 ~ "::: {#academic-tools}" {s=0; next}
|
||||||
|
$$1 != ":::" && s == 1 {print}
|
||||||
|
endef
|
||||||
|
export EXTRACT_ARTICLE
|
||||||
|
|
||||||
|
# Dependency includes.
|
||||||
|
include $(TMPDIR)make.depend
|
12
README.md
Normal file
12
README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# The Stanford Encyclopedia of Philosophy in ePub
|
||||||
|
|
||||||
|
Generate ePub documents for entries in the Stanford Encyclopedia of Philosophy.
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
Simply run `make` to build all articles in the SEP as separate ePub documents. Pass the
|
||||||
|
`ENABLE_KOBO=1` option for building Kobo ePub files instead (denoted by the `.kepub.epub` extension).
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
All code in this repository is covered by the terms of the MIT License, the full text of which can be found in the LICENSE file.
|
Loading…
Reference in New Issue
Block a user