KDr2
October 11, 2022, 2:46am
1
I want to add a favicon to my website which is built with scribble, but when I put something like
(make-head-extra ...)
into my scribble file, it tells me that:
not valid in document body (need a pre-part for decode) in: (head-extra...)
Anyone knows the way to use it? I failed to find an example from the official docs.
1 Like
Hi @KDr2
The idea is that head-extra
structures can be used in styles.
Here is an example:
(define (add-defaults doc pfx styl extras version?
#:html [html #f]
#:properties [properties null])
(struct-copy
part doc
[style (make-style (style-name (part-style doc))
; Add <script>...</script> to the <head>...</head> portion of html.
(append (style-properties (part-style doc)) ; existing styles
(list
; --- MathJax support ---
(head-extra ; This loads MathJax from mathjax-source
`(script ([type "text/javascript"] [src ,mathjax-source])))
(head-extra ; This loads the given extensions.
`(script ([type "text/x-mathjax-config"]) ,extentions)))))]))
1 Like
KDr2
October 11, 2022, 10:51am
3
Thanks, but where should I place this function and when/how to call it?
The function above was just meant to illustrate that
head-extra
is used with make-style
.
So something like this:
(make-style (head-extra ...))
KDr2
October 11, 2022, 12:08pm
5
Oh, thank you, I made it:
(define favicon (make-style
'favicon
(list (head-extra
'(link ([rel "shortcut icon"]
[type "image/png"]
[href "https://res.cloudinary.com/kdr2/image/upload/img-kdr2-com/main/jib-favicon.png"]))))))
and then
@title[#:style favicon]{...}
@section[#:style favicon]{...}
@section[#:style favicon]{...}
The last problem is that I should associate the style with every section to make all pages (each section a page) have that favicon. It there a way to write it only once and apply it to every page?
1 Like
You can make a new file "utils.rkt" and export your own versions and then
use @(require "utils.rkt")
in your scriible file:
Something like this (untested)
#lang racket
(provide (rename-out [my-title title]))
(define (my-title #:tag [tag #f] #:tag-prefix [prefix #f] #:style [style favicon]
#:version [version #f] #:date [date #f]
. str)
(keyword-apply title
'( #:date #:tag #:tag-prefix #:style #:version)
(list date tag prefix style version)
str))
I got the template for the my-title here:
2 Likes