mirror of
https://github.com/Findus23/lw1.at.git
synced 2024-09-10 05:13:46 +02:00
minor cleanup
This commit is contained in:
parent
103021146d
commit
c993c82ede
5 changed files with 53 additions and 45 deletions
40
assets/blurhash.ts
Normal file
40
assets/blurhash.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import {decode} from "blurhash";
|
||||
|
||||
const width = 32;
|
||||
const height = width / 2;
|
||||
|
||||
function drawBlurhash(canvasEl: HTMLCanvasElement) {
|
||||
const hash = canvasEl.getAttribute("data-blurhash")
|
||||
if (!hash) {
|
||||
return
|
||||
}
|
||||
|
||||
const pixels = decode(hash, width, height);
|
||||
|
||||
const ctx = canvasEl.getContext("2d")!;
|
||||
const imageData = new ImageData(pixels, width, height);
|
||||
// ctx.scale(10, 10);
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
ctx.drawImage(canvasEl, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
export function initBlurhash() {
|
||||
const canvasList: HTMLCanvasElement[] = Array.from(document.querySelectorAll("canvas[data-blurhash]"))
|
||||
canvasList.slice(0, 5)
|
||||
.forEach(drawBlurhash)
|
||||
|
||||
function loadRemaining() {
|
||||
canvasList.slice(5)
|
||||
.forEach(drawBlurhash)
|
||||
|
||||
}
|
||||
|
||||
if (canvasList.length > 5) {
|
||||
if (document.readyState !== "loading") {
|
||||
loadRemaining()
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", loadRemaining)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +1,9 @@
|
|||
import {decode} from "blurhash";
|
||||
import {initFeedback} from "./feedback";
|
||||
import {initSearch} from "./search";
|
||||
import {initMatomo} from "./matomo";
|
||||
import {initBlurhash} from "./blurhash";
|
||||
|
||||
const width = 32;
|
||||
const height = width / 2;
|
||||
|
||||
function drawBlurhash(canvasEl: HTMLCanvasElement) {
|
||||
const hash = canvasEl.getAttribute("data-blurhash")
|
||||
if (!hash) {
|
||||
return
|
||||
}
|
||||
|
||||
const pixels = decode(hash, width, height);
|
||||
|
||||
const ctx = canvasEl.getContext("2d")!;
|
||||
const imageData = new ImageData(pixels, width, height);
|
||||
// ctx.scale(10, 10);
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
ctx.drawImage(canvasEl, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
const canvasList: HTMLCanvasElement[] = Array.from(document.querySelectorAll("canvas[data-blurhash]"))
|
||||
canvasList.slice(0, 5)
|
||||
.forEach(drawBlurhash)
|
||||
|
||||
function loadRemaining() {
|
||||
canvasList.slice(5)
|
||||
.forEach(drawBlurhash)
|
||||
|
||||
}
|
||||
|
||||
if (canvasList.length > 5) {
|
||||
if (document.readyState !== "loading") {
|
||||
loadRemaining()
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", loadRemaining)
|
||||
}
|
||||
}
|
||||
|
||||
initBlurhash()
|
||||
initFeedback()
|
||||
initSearch()
|
||||
initMatomo()
|
||||
|
|
|
@ -7,7 +7,7 @@ def compress_files():
|
|||
for file in output_dir.glob("**/*"):
|
||||
if file.is_dir():
|
||||
continue
|
||||
if file.suffix not in {".html", ".css", ".js", ".xml", ".map", ".json", ".woff", ".woff2", ".ttf", ".svg"}:
|
||||
if file.suffix not in {".html", ".css", ".js", ".xml", ".map", ".json", ".ttf", ".svg"}:
|
||||
continue
|
||||
run(["gzip", "-k", "-f", "--best", str(file)], check=True)
|
||||
run(["brotli", "-f", "--best", str(file)], check=True)
|
||||
|
|
|
@ -2,7 +2,7 @@ import shutil
|
|||
from functools import cached_property
|
||||
from pathlib import Path
|
||||
from subprocess import run
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
import blurhash
|
||||
|
||||
|
@ -71,11 +71,11 @@ def logged_move(source: Path, target: Path):
|
|||
|
||||
|
||||
class File:
|
||||
def __init__(self, source_file: Path, type: str = None):
|
||||
def __init__(self, source_file: Path, type: Optional[Path] = None):
|
||||
self.source_file = source_file
|
||||
self.type = type
|
||||
self.public_url = None
|
||||
self.target_file = None
|
||||
self.public_url:Optional[str] = None
|
||||
self.target_file:Optional[str] = None
|
||||
|
||||
@property
|
||||
def modtime(self) -> float:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import List, Dict
|
||||
|
||||
|
@ -21,7 +22,7 @@ env = Environment(
|
|||
)
|
||||
|
||||
|
||||
class Generator:
|
||||
class Generator(ABC):
|
||||
template_name = "base.html"
|
||||
js_entry_point = "assets/main.ts"
|
||||
type = ""
|
||||
|
@ -40,6 +41,10 @@ class Generator:
|
|||
|
||||
self.template = env.get_template(self.template_name)
|
||||
|
||||
@abstractmethod
|
||||
def generate(self, writer: Writer) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class PostsGenerator(Generator):
|
||||
template_name = "page.html"
|
||||
|
|
Loading…
Reference in a new issue