jekyll-calibre 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fbbf254d6c7dec3597ffcd430b075a4a6dca0ab1e75f55b3632ce8155cc64576
4
+ data.tar.gz: 117d0e9cf2647b85ae5f5bc4792e16bbaaef17521d87294d6dc2f50273bf056a
5
+ SHA512:
6
+ metadata.gz: 7ad85f2dd1e70ccccf14e56904427b3122edea7b51c9651e392e50769564a631235c4550782ddf44bfbffcf7ff0b9f18915e7a60ebab75fe949c67c5c292d959
7
+ data.tar.gz: 7b61defe30a2f052585407a843c87ff329865844d4311ea0aeb19f352e30f34e94516e8c6af43b11b6a98068d80418eb38f50a9cfccd2a28d8d14623eeb66fd6
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 fauno <fauno@partidopirata.com.ar>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.es.md ADDED
@@ -0,0 +1,75 @@
1
+ # jekyll-calibre
2
+
3
+ Este plugin genera un sitio Jekyll a partir de una biblioteca de
4
+ Calibre, de forma que cualquier plantilla de Jekyll pude convertirse en
5
+ una biblioteca :)
6
+
7
+ Crea un artículo por cada libro en la biblioteca de Calibre,
8
+ convirtiendo los metadatos de Calibre en metadatos de Jekyll. Además
9
+ copia la cubierta y los archivos en el sitio final y los incorpora al
10
+ artículo como metadatos, para poder descargarlos.
11
+
12
+ ## Metadatos / "Frontmatter"
13
+
14
+ El plugin genera documentos de Jekyll como si fuesen archivos de la
15
+ colección `_posts` (está pendiente poder configurar la colección).
16
+
17
+ Si fueran escritos como archivos, quedarían así:
18
+
19
+ ```
20
+ ---
21
+ authors: [ Autorx, Autorx ]
22
+ title: Título del libro
23
+ slug: titulo-del-libro
24
+ date: (Fecha en que el libro se agregó a la biblioteca)
25
+ cover: /baseurl/url/absoluta/a/la/cubierta.jpg
26
+ files:
27
+ epub: /baseurl/url/absoluta/al/libro.epub
28
+ pdf: /baseurl/url/absoluta/al/libro.pdf
29
+ pubdate: (Fecha de publicación del libro)
30
+ publisher: [ Editora ]
31
+ ---
32
+
33
+ Comentarios del libro / Reseña
34
+ ```
35
+
36
+ ## Configuración
37
+
38
+ El plugin acepta estas opciones en `_config.yml`:
39
+
40
+ ```yaml
41
+ calibre:
42
+ dir: '/ruta/absoluta/a/la/biblioteca/de/calibre'
43
+ layout: plantilla
44
+ files:
45
+ dir: directorio/base/donde/se/copian/los/libros
46
+ cover:
47
+ field: campo-del-frontmatter-donde-van-las-cubiertas
48
+ dir: directorio/base/donde/se/copian/las/cubiertas
49
+ ```
50
+
51
+ * `calibre` es la base de la configuración del plugin
52
+ * `dir` es el directorio donde se encuentra la biblioteca de Calibre,
53
+ probablemente en tu `~`
54
+ * `layout` debe corresponder a un archivo dentro de `_layouts` y es la
55
+ plantilla para cada libro.
56
+ * `files` son las opciones relacionadas con archivos.
57
+ * `dir` dentro de `files` es el directorio donde se copian los archivos.
58
+ * `cover` son las opciones relacionadas con cubiertas.
59
+ * `dir` dentro de `cover` es el directorio donde se copian las
60
+ cubiertas.
61
+ * `field` es el campo del _frontmatter_ donde la plantilla espera
62
+ encontrar las imágenes de cubierta.
63
+
64
+ La única opción requerida es el directorio donde se encuentra la
65
+ biblioteca. Las opciones por defecto son:
66
+
67
+ ```yaml
68
+ calibre:
69
+ layout: post
70
+ files:
71
+ dir: files
72
+ cover:
73
+ dir: covers
74
+ field: cover
75
+ ```
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # jekyll-calibre
2
+
3
+ This Jekyll plugin creates a site from a Calibre library. So it's able
4
+ to turn *any* Jekyll theme into a library!
5
+
6
+ It creates a post for every book in a Calibre library, by mapping the
7
+ book's metadata into a post metadata. Then it copies the cover and the
8
+ files into the final site and also makes them available as metadata, so
9
+ the site can have download buttons.
10
+
11
+ ## Metadata / Frontmatter
12
+
13
+ The plugin will generate Jekyll documents as if they were files in the
14
+ `_posts` collection (it's on the `TODO` list to be able to configure the
15
+ collection).
16
+
17
+ If they were written down as actual files, they would end up like this:
18
+
19
+ ```
20
+ ---
21
+ authors: [ Author, Author ]
22
+ title: Book title
23
+ slug: book-title
24
+ date: (Date the book was added to the library)
25
+ cover: /baseurl/absolute/url/to/book/cover.jpg
26
+ files:
27
+ epub: /baseurl/absolute/url/to/book.epub
28
+ pdf: /baseurl/absolute/url/to/book.pdf
29
+ pubdate: (Publication date according to book)
30
+ publisher: [ Publisher ]
31
+ ---
32
+
33
+ Book comments
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ The plugin accepts these options in `_config.yml`:
39
+
40
+ ```yaml
41
+ calibre:
42
+ dir: '/absolute/path/to/calibre/library'
43
+ layout: default-layout-for-books
44
+ files:
45
+ dir: base/directory/where/files/are/stored/in/site
46
+ cover:
47
+ field: field-in-front-matter-where-covers-are-stored
48
+ dir: base/directory/where/covers/are/stored/in/site
49
+ ```
50
+
51
+ * `calibre` is the base for this plugin configuration
52
+ * `dir` is the Calibre library directory, it's probably in your home.
53
+ * `layout` must correspond to a file in `_layouts` and is the template
54
+ for each book.
55
+ * `files` are options related to files
56
+ * `dir` inside `files` is the directory where files are copied into
57
+ * `cover` are options related to covers
58
+ * `dir` inside `cover` is the directory where covers are copied into
59
+ * `field` is the frontmatter field where the theme expects to find
60
+ cover images
61
+
62
+ The only required option is the dir where the library is stored, the
63
+ default options are:
64
+
65
+ ```yaml
66
+ calibre:
67
+ layout: post
68
+ files:
69
+ dir: files
70
+ cover:
71
+ dir: covers
72
+ field: cover
73
+ ```
74
+
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll/calibre/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'jekyll-calibre'
8
+ gem.version = Jekyll::Calibre::VERSION
9
+ gem.authors = ['fauno']
10
+ gem.email = ['fauno@partidopirata.com.ar']
11
+ gem.description = %q{Jekyll plugin to generate a site from a Calibre library}
12
+ gem.summary = %q{Jekyll plugin to generate a site from a Calibre library}
13
+ gem.homepage = 'https://0xacab.org/utopias-piratas/jekyll-calibre'
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_dependency('calibre-ruby', '~> 0')
22
+ gem.add_dependency('jekyll', '~> 4')
23
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ class Calibre
3
+ VERSION = '0.0.2'.freeze
4
+ end
5
+ end
@@ -0,0 +1,97 @@
1
+ require 'calibre'
2
+
3
+ # Monkeypatch to Jekyll::Site
4
+ module Jekyll
5
+ class Site
6
+ alias_method :read_one, :read
7
+
8
+ # The goal here is to create books into posts without having to
9
+ # write them as actual files.
10
+ def read
11
+ # Read other posts normally
12
+ read_one
13
+
14
+ # Get the calibre dir from _config.yml
15
+ calibre_dir = config.dig('calibre','dir')
16
+ # Where to copy the covers
17
+ cover_dir = config.dig('calibre', 'cover', 'dir') || 'covers'
18
+
19
+ # TODO fail if calibre_dir is missing
20
+
21
+ # Open the database
22
+ Calibre.db = File.join(calibre_dir, 'metadata.db')
23
+
24
+ # For every book
25
+ # TODO make the query customizable
26
+ Calibre::Book.all.each do |book|
27
+ # Create a new document on the posts collection
28
+ # TODO use a _books collection
29
+ post = Jekyll::Document.new('unneeded', { site: self, collection: posts })
30
+
31
+ # The layout comes from the config
32
+ post.data['layout'] = config.dig('calibre', 'layout') || 'post'
33
+ # It's a markdown file
34
+ post.data['ext'] = 'markdown'
35
+ # The slug is the slugified title
36
+ post.data['slug'] = Utils.slugify(book.title)
37
+ # The title is the title :P
38
+ post.data['title'] = book.title
39
+ # Other metadata
40
+ post.data['date'] = book.timestamp
41
+ post.data['pubdate'] = book.pubdate
42
+ post.data['author'] = book.authors.map(&:name).compact
43
+ post.data['publisher'] = book.publishers.map(&:name).compact
44
+ # The content comes in html but we don't care much because
45
+ # markdown supports html
46
+ # TODO convert to markdown anyway in case the parser gives
47
+ # custom attributes and classes, like id's to h* tags
48
+ post.content = book.comments.map(&:text).compact.join
49
+
50
+ # The formats and files for easy access
51
+ # TODO fail if missing
52
+ files_dest = config.dig('calibre', 'files', 'dir') || 'files'
53
+ post.data['files'] = Hash[book.data.map do |f|
54
+ # Copy the actual files
55
+ file = File.join(files_dest, f.path)
56
+ file_dest = File.join(dest, file)
57
+ file_orig = File.join(calibre_dir, f.path)
58
+ FileUtils.mkdir_p(File.dirname(file_dest))
59
+ FileUtils.cp(file_orig, file_dest)
60
+ self.keep_files << file
61
+
62
+ # Also create a Hash { format: path } as absolute url
63
+ [ f.format, config.fetch('baseurl', '') + '/' + file ]
64
+ end]
65
+
66
+ # Copy the covers to the final site
67
+ if book.cover?
68
+ # Where in the metadata we want to store the path to cover
69
+ cover_field = config.dig('calibre', 'cover', 'field') || 'cover'
70
+ # The path is the absolute URL
71
+ post.data[cover_field] = "#{config.fetch('baseurl', '')}/#{cover_dir}/#{book.cover}"
72
+
73
+ # The cover is stored in a path mimicking the path from
74
+ # calibre
75
+ # TODO maybe use the slug or something, calibre uses spaces in
76
+ # directories :(
77
+ post_dir = File.join(dest, cover_dir, book.path)
78
+ # Original cover
79
+ cover = File.join(calibre_dir, book.cover)
80
+ # Final cover
81
+ dest_cover = File.join(post_dir, 'cover.jpg')
82
+
83
+ # Create the directory and copy the file
84
+ FileUtils.mkdir_p(post_dir)
85
+ FileUtils.cp(cover, dest_cover)
86
+
87
+ # Tell Jekyll to keep the files once finishes building
88
+ # keep_files needs the relative path
89
+ self.keep_files << File.join(cover_dir, book.cover)
90
+ end
91
+
92
+ # Add the book to the _posts collection
93
+ posts.docs << post
94
+ end
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-calibre
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - fauno
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: calibre-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jekyll
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
41
+ description: Jekyll plugin to generate a site from a Calibre library
42
+ email:
43
+ - fauno@partidopirata.com.ar
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.es.md
50
+ - README.md
51
+ - jekyll-calibre.gemspec
52
+ - lib/jekyll/calibre.rb
53
+ - lib/jekyll/calibre/version.rb
54
+ homepage: https://0xacab.org/utopias-piratas/jekyll-calibre
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.3.8
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Jekyll plugin to generate a site from a Calibre library
77
+ test_files: []