Skip to content

Commit

Permalink
Merge pull request #3040 from raspberrypi/iss-3035
Browse files Browse the repository at this point in the history
Custom template for integrating book links
  • Loading branch information
Alasdair Allan authored Aug 10, 2023
2 parents 6dff34e + f76c424 commit 4e0a787
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
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

0 comments on commit 4e0a787

Please sign in to comment.