Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom template for integrating book links #3040

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions jekyll-assets/_templates/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Slim::Helpers
def book_link
case (self.attr 'booktype')
when 'free'
%(You can <a href="#{self.attr 'link'}" target="_blank">download this book</a> as a PDF file for free, it has been released under a Creative Commons <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" target="_blank">Attribution-NonCommercial-ShareAlike</a> 3.0 Unported (CC BY NC-SA) licence.)
when 'buy'
%(You can <a href="#{self.attr 'link'}" target="_blank">buy this book</a> on the Raspberry Pi Press site.)
when 'donate'
%(You can <a href="#{self.attr 'link'}" target="_blank">download this book</a> for an optional donation on the Raspberry Pi Press site.)
else
return
end
end

def book_image
src = (self.attr 'image').dup
src = src.gsub(/^image::/, "")
src = src.gsub(/\[.*?\]$/, "")
return src
end

def section_title
if caption
captioned_title
elsif numbered && level <= (document.attr :sectnumlevels, 3).to_i
if level < 2 && document.doctype == 'book'
case sectname
when 'chapter'
%(#{(signifier = document.attr 'chapter-signifier') ? signifier.to_s + ' ' : ''}#{sectnum} #{title})
when 'part'
%(#{(signifier = document.attr 'part-signifier') ? signifier.to_s + ' ' : ''}#{sectnum nil, ':'} #{title})
else
%(#{sectnum} #{title})
end
else
%(#{sectnum} #{title})
end
else
title
end
end
end
50 changes: 50 additions & 0 deletions jekyll-assets/_templates/section.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- sect0 = level == 0
- if sect0
*{tag: %(h#{level + 1}), id: id, class: ('sect0' if sect0)}
- if id && (document.attr? :sectanchors)
a.anchor href="##{id}"
=section_title
- elsif id && (document.attr? :sectlinks)
a.link href="##{id}" =section_title
- else
=section_title
=content
- else
div class=[%(sect#{level}), role]
*{tag: %(h#{level + 1}), id: id, class: ('sect0' if sect0)}
- if id && (document.attr? :sectanchors)
a.anchor href="##{id}"
=section_title
- elsif id && (document.attr? :sectlinks)
a.link href="##{id}" =section_title
- else
=section_title
- if level == 1
.sectionbody
- if role? 'booklink'
div class="openblock float-group"
div class="content"
- if attr 'image'
div class="imageblock related thumb right"
div class="content"
a href=(attr 'link') target='_blank' class='image'
img src=(book_image)
=content
div class="paragraph"
p =book_link
- else
=content
- else
- if role? 'booklink'
div class="openblock float-group"
div class="content"
- if attr 'image'
div class="imageblock related thumb right"
div class="content"
a href=(attr 'link') target='_blank' class='image'
img src=(book_image)
=content
div class="paragraph"
p =book_link
- else
=content
Loading