BoboTiG / pep-epub

[Unofficial] Python PEP in EPUB format
11 stars 1 forks source link

Single epub #7

Open joelsgp opened 1 year ago

joelsgp commented 1 year ago

It would be helpful to have every pep packaged in a single epub with working links to one another - like what's provided at https://docs.python.org/3.10/download.html

Upvote & Fund

Fund with Polar

joelsgp commented 1 year ago

I found a way to combine them in calibre with the epupmerge plugin, but it would be useful to have Series metadata on each one for sorting

BoboTiG commented 1 year ago

I'm not familiar with series metadata, and I'm not against such features.

I'm open for pull requests, if you wanted to give a try :)

joelsgp commented 1 year ago

I found this https://github.com/kovidgoyal/calibre/blob/master/src/calibre/ebooks/metadata/opf2.py to use as a reference for metadata keys, then I started doing this:

@@ -6,11 +6,14 @@ convert() {
     local pep
     local output
     local title
+    local date

     file="$1"
     output="$(echo "${file}" | sed s'#.rst$#.epub# ; s#.txt$#.epub#')"
     pep="$(head -1 "${file}")"
     title="$(head -2 "${file}" | tail -1 | sed 's/Title: // ; s/"/\"/g')"
+    date="$(grep "Created:" "${file}"| sed 's/Created: // ; s/"/\"/g')"
+    date="$(date --date=${date} '+%Y-%m-%d')"

     echo ">>> Processing ${pep} (${title}) ..."
     pandoc \
@@ -23,6 +26,7 @@ convert() {
         --metadata="creator:Python" \
         --metadata="language:en" \
         --metadata="title:${pep} (${title})" \
+        --metadata="date:${date}" \
         --output="../peps_epub/${output}" \
         "${file}"
 }

to sort by publishing date, however I then found this https://github.com/python/peps/pull/1995 which is probably a more efficient route than using pandoc