bridgetown_writebook 0.1.0.4 → 0.1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3261ad7395bbf6eecfbd7eb4cdadb40b8c5ae3c6fc9dcee4eda240143e600a5d
4
- data.tar.gz: 707e4df1f4123dc443fd534e4d87c6f6d9b03089354f0cb5df27f19949eb8902
3
+ metadata.gz: 853112445729a49c6d145ac9c26f3f2e1a2f7c710f2ba381ccda63e041f9095e
4
+ data.tar.gz: 6596c9cc2a7f1c58e047865bdecce10a9a5141a1a0804a69d4156b2108814c08
5
5
  SHA512:
6
- metadata.gz: 5a74f861a36adf17d0f79db9b82b0cefae1c8fda2c741ab24fed183e3b5a261330bc77a88bf96983fa3c1831b04c62a32d4ab61eb01533c9a7e20af75dee64e9
7
- data.tar.gz: f4065417c9ac921d19ba8500ff76ed162e78f1d6a1e44ad44344a68f479b1b1c695c8989871f80a23ca67b229da2f3b7c7e2d93d168e2af98fc528bdea79063f
6
+ metadata.gz: acb90d878cd3ef4717070f050b4c8942a0edc3b694fd027d1ba1976233a7d150cb2fc364f19959e9b6f56701b6691ba0f801728372ccf0c94f3bf13fae7d8e74
7
+ data.tar.gz: 26cd34f2c2f86e12af0e955eaef910134fb0577eaf811671638e8dd080c5ec98f08139362c69ae0e552069acd3359d17d60988d7571d80defcb85bde25d62c7a
data/README.md CHANGED
@@ -1,67 +1,49 @@
1
- # Sample plugin for Bridgetown
1
+ # Bridgetown Writebook
2
2
 
3
- _NOTE: This isn't a real plugin! Copy this sample code and use it to create your own Ruby gem! [Help guide here…](https://www.bridgetownrb.com/docs/plugins)_ 😃
4
-
5
- _You can run_ `bridgetown plugins new` _to easily set up a customized version of this starter repo._
6
-
7
- A Bridgetown plugin to [fill in the blank]…
3
+ A Bridgetown plugin to add [WriteBook](https://once.com/writebook) style books to your static website.
8
4
 
9
5
  ## Installation
10
6
 
11
7
  Run this command to add this plugin to your site's Gemfile:
12
8
 
13
9
  ```shell
14
- bundle add my_awesome_plugin
15
- ```
16
-
17
- Then add the initializer to your configuration in `config/initializers.rb`:
18
-
19
- ```ruby
20
- init :my_awesome_plugin
21
- ```
22
-
23
- Or if there's a `bridgetown.automation.rb` automation script, you can run that instead for guided setup:
24
-
25
- ```shell
26
- bin/bridgetown apply https://github.com/username/my_awesome_plugin
10
+ bundle add bridgetown_writebook
27
11
  ```
28
12
 
29
13
  ## Usage
30
14
 
31
- The plugin will…
32
-
33
- ### Optional configuration options
34
-
35
- The plugin will automatically use any of the following metadata variables if they are present in your site's `_data/site_metadata.yml` file.
36
-
37
-
38
-
39
- ## Testing
15
+ After installation, the plugin provides a complete book management system for your Bridgetown site. Books are organized as collections, with each book containing multiple chapters.
40
16
 
41
- * Run `bundle exec rake test` to run the test suite
42
- * Or run `script/cibuild` to validate with Rubocop and Minitest together.
17
+ ### Creating Your First Book
43
18
 
44
- ## Contributing
19
+ 1. **Set up the books infrastructure** (one-time setup):
20
+ ```shell
21
+ bridgetown book setup
22
+ ```
23
+ This creates the necessary folder structure and adds the books collection to your Bridgetown configuration.
45
24
 
46
- 1. Fork it (https://github.com/username/my-awesome-plugin/fork)
47
- 2. Clone the fork using `git clone` to your local development machine.
48
- 3. Create your feature branch (`git checkout -b my-new-feature`)
49
- 4. Commit your changes (`git commit -am 'Add some feature'`)
50
- 5. Push to the branch (`git push origin my-new-feature`)
51
- 6. Create a new Pull Request
25
+ 2. **Create a new book**:
26
+ ```shell
27
+ bridgetown book new --title "My Awesome Book"
28
+ ```
29
+ This creates a folder under `src/_books/` with an initial metadata file.
52
30
 
53
- ----
31
+ 3. **Add chapters to your book**:
32
+ ```shell
33
+ bridgetown book chapters add --book "My Awesome Book" --title "Introduction"
34
+ ```
35
+ Chapters are automatically numbered and added to your book's folder.
54
36
 
55
- ## Releasing (you can delete this section in your own plugin repo)
37
+ ### Book Structure
56
38
 
57
- To release a new version of the plugin, simply bump up the version number in both `version.rb` and
58
- `package.json`, and then run `script/release`. This will require you to have a registered account
59
- with both the [RubyGems.org](https://rubygems.org) and [NPM](https://www.npmjs.com) registries.
60
- You can optionally remove the `package.json` and `frontend` folder if you don't need to package frontend
61
- assets for Webpack.
39
+ Each book consists of:
40
+ - A metadata file (`00-meta.md`) containing title, subtitle, and authors
41
+ - Numbered chapter files (e.g., `01-introduction.md`, `02-getting-started.md`)
42
+ - An optional cover image (`cover.png` in the book's folder)
62
43
 
63
- If you run into any problems or need further guidance, please check out our [Bridgetown community resources](https://www.bridgetownrb.com/docs/community)
64
- where friendly folks are standing by to help you build and release your plugin or theme.
44
+ ### Accessing Your Books
65
45
 
66
- **NOTE:** make sure you add the `bridgetown-plugin` [topic](https://github.com/topics/bridgetown-plugin) to your
67
- plugin's GitHub repo so the plugin or theme will show up on [Bridgetown's official Plugin Directory](https://www.bridgetownrb.com/plugins)! (There may be a day or so delay before you see it appear.)
46
+ The plugin automatically generates:
47
+ - A books index page at `/books/` listing all your books
48
+ - Individual book pages at `/books/[book-slug]/` showing chapters
49
+ - Chapter pages with navigation between previous/next chapters
@@ -5,10 +5,10 @@ require_relative "lib/bridgetown_writebook/version"
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "bridgetown_writebook"
7
7
  spec.version = BridgetownWritebook::VERSION
8
- spec.author = "Bridgetown Team"
9
- spec.email = "maintainers@bridgetownrb.com"
10
- spec.summary = "Sample code for creating new Bridgetown plugins"
11
- spec.homepage = "https://github.com/username/bridgetown_writebook"
8
+ spec.author = "Syed Muhammad Sawaid"
9
+ spec.email = "smsawaid3@gmail.com"
10
+ spec.summary = "WriteBook style books for your static website"
11
+ spec.homepage = "https://github.com/syedmsawaid/bridgetown_writebook"
12
12
  spec.license = "MIT"
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script|spec|features|frontend)/!) }
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownWritebook
4
+ class BookContent < Bridgetown::Component
5
+ def initialize(book:)
6
+ super
7
+ @book = book
8
+ end
9
+
10
+ def template
11
+ html do
12
+ ul class: "book-content-list",
13
+ data: {
14
+ controller: "bookmark",
15
+ bookmark_chapter_outlet: ".chapter",
16
+ bookmark_book_value: @book.id,
17
+ } do
18
+ text_node chapters_list.join
19
+ end
20
+ end
21
+ end
22
+
23
+ def chapters_list
24
+ @book.chapters.map do |chapter|
25
+ BridgetownWritebook::ChapterListItem.new(chapter: chapter).template
26
+ end.join
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownWritebook
4
+ class BookCover < Bridgetown::Component
5
+ attr_accessor :book
6
+
7
+ def initialize(book:)
8
+ super
9
+ @book = book
10
+ end
11
+
12
+ def template
13
+ html do
14
+ li class: "book-cover-item",
15
+ data: cover_data_attributes do
16
+ a class: "book-cover-link", href: book.link do
17
+ render_cover_image
18
+ render_book_title
19
+ render_book_authors
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def cover_data_attributes
28
+ chapters_json = book.chapter_ids.to_json.gsub('"', "&quot;")
29
+ {
30
+ controller: "book",
31
+ book_id_value: book.id,
32
+ book_chapters_value: chapters_json,
33
+ }
34
+ end
35
+
36
+ def render_cover_image
37
+ div class: "book-cover-image-wrapper",
38
+ data: { book_target: "cover" } do
39
+ img src: book.cover, class: "book-cover-image"
40
+ end
41
+ end
42
+
43
+ def render_book_title
44
+ div class: "book-cover-title" do
45
+ text_node book.name
46
+ end
47
+ end
48
+
49
+ def render_book_authors
50
+ div class: "book-cover-authors" do
51
+ text_node book.authors
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownWritebook
4
+ class BookList < Bridgetown::Component
5
+ def initialize(books:)
6
+ super
7
+ @books = books
8
+ end
9
+
10
+ def book_covers
11
+ @books.map { |book| BridgetownWritebook::BookCover.new(book: book).template }.join
12
+ end
13
+
14
+ def template
15
+ html do
16
+ ul class: "book-list" do
17
+ text_node book_covers
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownWritebook
4
+ class ChapterContent < Bridgetown::Component
5
+ def initialize(chapter:)
6
+ super
7
+ @chapter = chapter
8
+ end
9
+
10
+ def template
11
+ html do
12
+ text_node @chapter.resource.content
13
+ div data: {
14
+ controller: "reading",
15
+ reading_id_value: @chapter.id,
16
+ reading_book_value: @chapter.book.id,
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BridgetownWritebook
4
+ class ChapterListItem < Bridgetown::Component
5
+ attr_accessor :chapter
6
+
7
+ def initialize(chapter:)
8
+ super
9
+ @chapter = chapter
10
+ end
11
+
12
+ def template
13
+ html do
14
+ li class: "chapter",
15
+ data: {
16
+ controller: "chapter",
17
+ chapter_id_value: chapter.id,
18
+ chapter_ellipsis_class: "chapter-highlight",
19
+ } do
20
+ a class: "chapter-link", href: chapter.link do
21
+ text_node chapter.title
22
+ end
23
+ span class: "chapter-ellipsis", data: { chapter_target: "ellipsis" }
24
+ span class: "chapter-word-count" do
25
+ text_node chapter.word_count
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ ---
2
+ layout: default
3
+ ---
4
+ <div class="breadcrumb-nav">
5
+ <a href="/books">Books</a>
6
+ <span>▸</span>
7
+ <strong>{{ page.title }}</strong>
8
+ </div>
9
+
10
+ <div class="book-layout-container">
11
+ <div class="book-sidebar">
12
+ <img src="{{ page.data.cover }}" alt="{{ page.title }}" class="book-sidebar-image">
13
+ </div>
14
+
15
+ <div class="book-main-content">
16
+ <h1 class="book-title">{{ page.title }}</h1>
17
+ <div>{{ page.data.subtitle }}</div>
18
+ <div>{{ page.data.authors }}</div>
19
+
20
+ {{ content }}
21
+ </div>
22
+ </div>
@@ -0,0 +1,59 @@
1
+ ---
2
+ layout: default
3
+ ---
4
+ <div class="breadcrumb-nav">
5
+ <a href="/books">Books</a>
6
+ <span>▸</span>
7
+ <a href="{{ page.book_link }}">{{ page.book_title }}</a>
8
+ <span>▸</span>
9
+ <strong>{{ page.title }}</strong>
10
+ </div>
11
+
12
+ <div class="chapter-header">
13
+ <h1 class="chapter-title">{{ page.title }}</h1>
14
+ </div>
15
+
16
+ {{ content }}
17
+
18
+ <div class="chapter-navigation">
19
+ <div class="chapter-nav-button">
20
+ {% if page.next_chapter_title %}
21
+ <a class="chapter-nav-link" href="{{ page.next_chapter_link }}"
22
+ >Next: {{ page.next_chapter_title }}
23
+ <svg
24
+ xmlns="http://www.w3.org/2000/svg"
25
+ width="24"
26
+ height="24"
27
+ viewBox="0 0 24 24"
28
+ fill="none"
29
+ stroke="currentColor"
30
+ stroke-width="2"
31
+ stroke-linecap="round"
32
+ stroke-linejoin="round"
33
+ class="lucide lucide-arrow-right-icon lucide-arrow-right"
34
+ >
35
+ <path d="M5 12h14"/><path d="m12 5 7 7-7 7"/>
36
+ </svg>
37
+ </a>
38
+ {% else %}
39
+ <a class="chapter-nav-link" href="{{ page.book_link }}"
40
+ >Table of contents: {{ page.book_title }}
41
+ <svg
42
+ xmlns="http://www.w3.org/2000/svg"
43
+ width="24"
44
+ height="24"
45
+ viewBox="0 0 24 24"
46
+ fill="none"
47
+ stroke="currentColor"
48
+ stroke-width="2"
49
+ stroke-linecap="round"
50
+ stroke-linejoin="round"
51
+ class="lucide lucide-undo2-icon lucide-undo-2"
52
+ >
53
+ <path d="M9 14 4 9l5-5"/>
54
+ <path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>
55
+ </svg>
56
+ </a>
57
+ {% endif %}
58
+ </div>
59
+ </div>
@@ -1,15 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support/core_ext/numeric/conversions"
4
+ require_relative "models/book"
5
+ require_relative "models/chapter"
6
+
3
7
  module BridgetownWritebook
4
8
  class Builder < Bridgetown::Builder
9
+ def initialize(name = nil, current_site = nil)
10
+ Bridgetown.logger.info "Generating books..."
11
+ super
12
+ @books = []
13
+ end
14
+
5
15
  def build
6
- liquid_tag "bridgetown_writebook" do
7
- "This plugin works!"
16
+ generator do
17
+ Bridgetown.logger.info "Running book generator..."
18
+ create_book_objects
19
+ generate_books
20
+ generate_index_page_for_books
21
+ end
22
+ end
23
+
24
+ def generate_index_page_for_books
25
+ template = BridgetownWritebook::BookList.new(books: @books).template
26
+ add_resource :pages, "books.md" do
27
+ layout "default"
28
+ permalink "/books/"
29
+ content template
8
30
  end
31
+ end
32
+
33
+ def create_book_objects # rubocop:disable Metrics/AbcSize
34
+ site.collections.books.resources
35
+ .group_by { |b| b.id.split("_books/").last.split("/").first }
36
+ .each do |book_id, chapters|
37
+ meta_file = chapters.find { |c| c.relative_path.to_s.end_with?("00-meta.md") }
38
+ regular_chapters = chapters.reject { |c| c.relative_path.to_s.end_with?("00-meta.md") }
9
39
 
10
- liquid_tag "what" do
11
- "is going on"
40
+ resource = add_resource(:book, "books/#{book_id}.md") { permalink "/books/:slug/" }
41
+ @books << BridgetownWritebook::Models::Book.new(
42
+ resource, chapters: regular_chapters, meta: meta_file
43
+ )
12
44
  end
13
45
  end
46
+
47
+ def generate_books
48
+ @books.each(&:generate)
49
+ end
14
50
  end
15
51
  end
@@ -33,6 +33,7 @@ module BridgetownWritebook
33
33
  end
34
34
 
35
35
  file_path = File.join(folder_path, "00-meta.md")
36
+ # rubocop:disable Bridgetown/InsecureHeredoc
36
37
  content = <<~MARKDOWN
37
38
  ---
38
39
  title: #{title}
@@ -40,6 +41,7 @@ module BridgetownWritebook
40
41
  authors: [ ]
41
42
  ---
42
43
  MARKDOWN
44
+ # rubocop:enable Bridgetown/InsecureHeredoc
43
45
 
44
46
  File.write(file_path, content)
45
47
  Bridgetown.logger.info "Creating a new book with title: #{title}"
@@ -16,13 +16,17 @@ module BridgetownWritebook
16
16
  return
17
17
  end
18
18
 
19
- chapter_file = File.join(@folder_path, "#{new_chapter_number}-#{chapter_title.parameterize}.md")
19
+ chapter_file = File.join(
20
+ @folder_path, "#{new_chapter_number}-#{chapter_title.parameterize}.md"
21
+ )
20
22
 
23
+ # rubocop:disable Bridgetown/InsecureHeredoc
21
24
  content = <<~MARKDOWN
22
25
  ---
23
26
  title: #{chapter_title}
24
27
  ---
25
28
  MARKDOWN
29
+ # rubocop:enable Bridgetown/InsecureHeredoc
26
30
 
27
31
  File.write(chapter_file, content)
28
32
  Bridgetown.logger.info "Chapter created: #{chapter_file}"
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "chapter"
4
+
3
5
  module BridgetownWritebook
4
6
  module Models
5
7
  class Book
@@ -14,7 +16,7 @@ module BridgetownWritebook
14
16
  @chapters = []
15
17
 
16
18
  chapters.each do |chapter|
17
- @chapters << Chapter.new(chapter, booxk: self)
19
+ @chapters << Chapter.new(chapter, book: self)
18
20
  end
19
21
 
20
22
  extract_metadata
@@ -33,7 +35,7 @@ module BridgetownWritebook
33
35
  "by #{@authors.join(", ")}" if authors?
34
36
  end
35
37
 
36
- def extract_metadata
38
+ def extract_metadata # rubocop:disable Metrics/CyclomaticComplexity
37
39
  @name = @meta&.data&.title || slug.titleize
38
40
  @subtitle = @meta&.data&.subtitle
39
41
  @authors = @meta&.data&.authors
@@ -51,42 +53,16 @@ module BridgetownWritebook
51
53
  chapters.map(&:id)
52
54
  end
53
55
 
54
- def generate
55
- resource.data.layout = :book
56
+ def generate # rubocop:disable Metrics/AbcSize
57
+ resource.data.layout = "bridgetown_writebook/book"
56
58
  resource.data.title = title
57
59
  resource.data.cover = cover
58
60
  resource.data.subtitle = subtitle
59
61
  resource.data.authors = authors
60
- resource.content = content
62
+ resource.content = BridgetownWritebook::BookContent.new(book: self).template
61
63
 
62
64
  chapters.each(&:generate)
63
65
  end
64
-
65
- def content
66
- <<~HTML
67
- <ul class="pl-0" data-controller="bookmark" data-bookmark-chapter-outlet='.chapter' data-bookmark-book-value="#{id}">
68
- #{chapters.map do |chapter|
69
- li chapter
70
- end.join }
71
- </ul>
72
- HTML
73
- end
74
-
75
- # TODO: may be convert these into compenents or partials.
76
- # TODO: Move them to the template, add it to the metadata and move it to the template.
77
- def li(chapter)
78
- <<~HTML
79
- <li class='chapter flex justify-between items-end gap-4'
80
- data-controller='chapter'
81
- data-chapter-id-value='#{chapter.id}'
82
- data-chapter-ellipsis-class="text-orange-500"
83
- >
84
- <a href='#{chapter.link}' class="text-nowrap">#{chapter.title}</a>
85
- <span class="grow overflow-hidden border-b border-dotted border-black mb-1.5" data-chapter-target="ellipsis"></span>
86
- <span class="text-nowrap">#{chapter.word_count}</span>
87
- </li>
88
- HTML
89
- end
90
66
  end
91
67
  end
92
68
  end
@@ -42,20 +42,14 @@ module BridgetownWritebook
42
42
  book.chapters[book.chapters.index(self) + 1]
43
43
  end
44
44
 
45
- def generate
46
- resource.data.layout = "chapter"
45
+ def generate # rubocop:disable Metrics/AbcSize
46
+ resource.data.layout = "bridgetown_writebook/chapter"
47
47
  resource.data.book_title = book.name
48
48
  resource.data.book_link = book.link
49
49
  resource.data.next_chapter_title = next_chapter&.title
50
50
  resource.data.next_chapter_link = next_chapter&.link
51
51
  resource.data.word_count = word_count
52
- resource.content = <<~HTML
53
- #{html resource.content}
54
- <div data-controller="reading"
55
- data-reading-id-value="#{id}"
56
- data-reading-book-value="#{book.id}">
57
- </div>
58
- HTML
52
+ resource.content = BridgetownWritebook::ChapterContent.new(chapter: self).template
59
53
  end
60
54
  end
61
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BridgetownWritebook
4
- VERSION = "0.1.0.4"
4
+ VERSION = "0.1.0.8"
5
5
  end
data/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "bridgetown_writebook",
3
- "version": "0.1.0",
3
+ "version": "0.1.0.8",
4
4
  "main": "frontend/javascript/index.js",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "https://github.com/username/bridgetown_writebook.git"
7
+ "url": "https://github.com/syedmsawaid/bridgetown_writebook.git"
8
8
  },
9
- "author": "Bridgetown Maintainers <maintainers@bridgetownrb.com>",
9
+ "author": "Syed Muhammad Sawaid <smsawaid3@gmail.com>",
10
10
  "homepage": "https://www.bridgetownrb.com",
11
11
  "license": "MIT",
12
12
  "private": false,
13
13
  "files": [
14
14
  "frontend"
15
15
  ]
16
- }
16
+ }
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown_writebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.4
4
+ version: 0.1.0.8
5
5
  platform: ruby
6
6
  authors:
7
- - Bridgetown Team
8
- autorequire:
7
+ - Syed Muhammad Sawaid
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-08-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bridgetown
@@ -72,8 +71,7 @@ dependencies:
72
71
  - - "~>"
73
72
  - !ruby/object:Gem::Version
74
73
  version: '0.3'
75
- description:
76
- email: maintainers@bridgetownrb.com
74
+ email: smsawaid3@gmail.com
77
75
  executables: []
78
76
  extensions: []
79
77
  extra_rdoc_files: []
@@ -92,10 +90,17 @@ files:
92
90
  - Rakefile
93
91
  - bridgetown.automation.rb
94
92
  - bridgetown_writebook.gemspec
93
+ - components/bridgetown_writebook/book_content.rb
94
+ - components/bridgetown_writebook/book_cover.rb
95
+ - components/bridgetown_writebook/book_list.rb
96
+ - components/bridgetown_writebook/chapter_content.rb
97
+ - components/bridgetown_writebook/chapter_list_item.rb
95
98
  - components/bridgetown_writebook/layout_help.liquid
96
99
  - components/bridgetown_writebook/plugin_component.rb
97
100
  - content/bridgetown_writebook/example_page.md
98
101
  - content/bridgetown_writebook/train-on-rails.jpeg
102
+ - layouts/bridgetown_writebook/book.liquid
103
+ - layouts/bridgetown_writebook/chapter.liquid
99
104
  - layouts/bridgetown_writebook/layout.html
100
105
  - lib/bridgetown_writebook.rb
101
106
  - lib/bridgetown_writebook/builder.rb
@@ -103,14 +108,12 @@ files:
103
108
  - lib/bridgetown_writebook/commands/chapter.rb
104
109
  - lib/bridgetown_writebook/models/book.rb
105
110
  - lib/bridgetown_writebook/models/chapter.rb
106
- - lib/bridgetown_writebook/models/something.rb
107
111
  - lib/bridgetown_writebook/version.rb
108
112
  - package.json
109
- homepage: https://github.com/username/bridgetown_writebook
113
+ homepage: https://github.com/syedmsawaid/bridgetown_writebook
110
114
  licenses:
111
115
  - MIT
112
116
  metadata: {}
113
- post_install_message:
114
117
  rdoc_options: []
115
118
  require_paths:
116
119
  - lib
@@ -125,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
128
  - !ruby/object:Gem::Version
126
129
  version: '0'
127
130
  requirements: []
128
- rubygems_version: 3.5.13
129
- signing_key:
131
+ rubygems_version: 3.7.2
130
132
  specification_version: 4
131
- summary: Sample code for creating new Bridgetown plugins
133
+ summary: WriteBook style books for your static website
132
134
  test_files: []
@@ -1,63 +0,0 @@
1
- require 'active_support/core_ext/numeric/conversions'
2
-
3
- # frozen_string_literal: true
4
- class Builders::Books < SiteBuilder
5
- def initialize(name = nil, current_site = nil)
6
- super
7
- @books = []
8
- end
9
-
10
- def build
11
- generator do
12
- create_book_objects
13
- generate_books
14
- generate_index_page_for_books
15
- end
16
- end
17
-
18
- def generate_index_page_for_books
19
- books = @books
20
- book_covers = books.map { |book| cover_for(book) }.join
21
- add_resource nil, "books.md" do
22
- layout "default"
23
- permalink "/books/"
24
- content <<-HTML
25
- <ul class="list-none flex justify-center sm:grid sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-y-6 py-10 px-0 flex-wrap">
26
- #{book_covers}
27
- </ul>
28
- HTML
29
- end
30
- end
31
-
32
- def cover_for(book)
33
- chapters_json = book.chapter_ids.to_json.gsub('"', '&quot;')
34
-
35
- <<-HTML
36
- <li data-controller="book" data-book-id-value="#{book.id}" data-book-chapters-value="#{chapters_json}" >
37
- <a class="flex flex-col gap-2 max-w-[236px]" href="#{book.link}">
38
- <div class="max-h-[378px] border rounded relative box-border" data-book-target="cover">
39
- <img src="#{book.cover}" class="max-h-[378px] max-w-[236px] rounded">
40
- </div>
41
- <div class="text-center">#{book.name}</div>
42
- <div class="text-sm text-center">#{book.authors}</div>
43
- </a>
44
- </li>
45
- HTML
46
- end
47
-
48
- def create_book_objects
49
- site.collections.books.resources
50
- .group_by { |b| b.id.split("_books/").last.split("/").first }
51
- .each do |book_id, chapters|
52
- meta_file = chapters.find { |c| c.relative_path.to_s.end_with?('00-meta.md') }
53
- regular_chapters = chapters.reject { |c| c.relative_path.to_s.end_with?('00-meta.md') }
54
-
55
- resource = add_resource(:book, "books/#{book_id}.md") { permalink "/books/:slug/" }
56
- @books << Book.new(resource, chapters: regular_chapters, meta: meta_file)
57
- end
58
- end
59
-
60
- def generate_books
61
- @books.each(&:generate)
62
- end
63
- end