mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
Change back to sync stylesheets to prevent FOUC in Firefox & Chrome
This commit is contained in:
parent
da56d10818
commit
eb90c07585
2 changed files with 6 additions and 21 deletions
|
|
@ -24,23 +24,6 @@ extension Node where Context == HTML.HeadContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Node where Context == HTML.BodyContext {
|
|
||||||
static func asyncStylesheetLinks(_ urls: [URLRepresentable]) -> Self {
|
|
||||||
.script("""
|
|
||||||
(function() {
|
|
||||||
var urls = [\(urls.map { "'\($0)'" }.joined(separator: ", "))];
|
|
||||||
urls.forEach(function(url) {
|
|
||||||
var css = document.createElement('link');
|
|
||||||
css.href = url;
|
|
||||||
css.rel = 'stylesheet';
|
|
||||||
css.type = 'text/css';
|
|
||||||
document.getElementsByTagName('head')[0].appendChild(css);
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
""")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension Node where Context == HTML.BodyContext {
|
extension Node where Context == HTML.BodyContext {
|
||||||
static func time(_ nodes: Node<HTML.BodyContext>...) -> Self {
|
static func time(_ nodes: Node<HTML.BodyContext>...) -> Self {
|
||||||
.element(named: "time", nodes: nodes)
|
.element(named: "time", nodes: nodes)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ import Plot
|
||||||
|
|
||||||
enum Template {
|
enum Template {
|
||||||
static func site(body: Node<HTML.BodyContext>, context: TemplateContext) -> HTML {
|
static func site(body: Node<HTML.BodyContext>, context: TemplateContext) -> HTML {
|
||||||
HTML(.lang("en"),
|
HTML(
|
||||||
|
.lang("en"),
|
||||||
.comment("meow"),
|
.comment("meow"),
|
||||||
.head(
|
.head(
|
||||||
.encoding(.utf8),
|
.encoding(.utf8),
|
||||||
|
|
@ -30,7 +31,10 @@ enum Template {
|
||||||
.meta(.name("theme-color"), .content("#ffffff")),
|
.meta(.name("theme-color"), .content("#ffffff")),
|
||||||
.link(.rel(.dnsPrefetch), .href("https://use.typekit.net")),
|
.link(.rel(.dnsPrefetch), .href("https://use.typekit.net")),
|
||||||
.link(.rel(.dnsPrefetch), .href("https://netdna.bootstrapcdn.com")),
|
.link(.rel(.dnsPrefetch), .href("https://netdna.bootstrapcdn.com")),
|
||||||
.link(.rel(.dnsPrefetch), .href("https://gist.github.com"))
|
.link(.rel(.dnsPrefetch), .href("https://gist.github.com")),
|
||||||
|
.group(context.styles.map { url in
|
||||||
|
.link(.rel(.stylesheet), .type("text/css"), .href(url))
|
||||||
|
})
|
||||||
),
|
),
|
||||||
.body(
|
.body(
|
||||||
.header(.class("primary"),
|
.header(.class("primary"),
|
||||||
|
|
@ -60,8 +64,6 @@ enum Template {
|
||||||
.a(.href(context.url(for: "about")), .text(context.site.author))
|
.a(.href(context.url(for: "about")), .text(context.site.author))
|
||||||
),
|
),
|
||||||
|
|
||||||
.asyncStylesheetLinks(context.styles),
|
|
||||||
|
|
||||||
.group(context.scripts.map { script in
|
.group(context.scripts.map { script in
|
||||||
.script(.attribute(named: "defer"), .src(script))
|
.script(.attribute(named: "defer"), .src(script))
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue