Skip to content

Commit

Permalink
Merge pull request #3082 from raspberrypi/iss-3060
Browse files Browse the repository at this point in the history
Custom template for tutorial sections
  • Loading branch information
Alasdair Allan authored Aug 25, 2023
2 parents 1cb55e5 + 786b251 commit 21d3294
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions jekyll-assets/_templates/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'net/http'

module Slim::Helpers
def book_link
case (self.attr 'booktype')
Expand All @@ -19,6 +21,24 @@ def book_image
return src
end

def tutorial_image
uri = URI(self.attr 'link')
source = Net::HTTP.get(uri)
# get the short description
desc = ""
desc_arr = /<meta[^>]+name="description"[^>]+content="([^>]+)"[^>]*>/.match(source)
if desc_arr
desc = desc_arr[1]
end
# get the image source
img_src = ""
img_arr = /<meta[^>]+property="og:image"[^>]+content="([^>]+)"[^>]*>/.match(source)
if img_arr
img_src = img_arr[1]
end
return '<a href="'+(self.attr 'link')+'" target="_blank" class="image"><div class="tutorialcard"><img src="'+img_src+'"/><p class="caption">'+desc+'</p></div></a>'
end

def section_title
if caption
captioned_title
Expand Down
14 changes: 14 additions & 0 deletions jekyll-assets/_templates/section.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
=content
div class="paragraph"
p =book_link
- elsif role? 'tutoriallink'
div class="openblock float-group"
div class="content"
div class="imageblock related thumb right"
div class="content"
=tutorial_image
=content
- else
=content
- else
Expand All @@ -46,5 +53,12 @@
=content
div class="paragraph"
p =book_link
- elsif role? 'tutoriallink'
div class="openblock float-group"
div class="content"
div class="imageblock related thumb right"
div class="content"
=tutorial_image
=content
- else
=content
14 changes: 14 additions & 0 deletions jekyll-assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,20 @@ div.videoblock iframe {
margin-bottom: 10px;
}

/* TUTORIAL BLOCKS */

#content .tutorialcard {
max-width: 400px;
border: 1px solid #dedede;
border-radius: 5px;
}

#content .tutorialcard p.caption {
padding-left: 10px;
padding-right: 10px;
font-size: 0.9em;
}

/* DOXYGEN ELEMENTS */

div.memproto {
Expand Down

0 comments on commit 21d3294

Please sign in to comment.