Browse Source

generate-item.tcl: replace with gen-screenshot.ts

pull/32/head
D. Bohdan 1 year ago
parent
commit
08cf8c7902
  1. 58
      gen-screenshot.ts
  2. 43
      generate-item.tcl
  3. 4
      screenshot-page.html

58
gen-screenshot.ts

@ -0,0 +1,58 @@
#! /usr/bin/env -S deno run --allow-run --allow-read --allow-write
// Generate the screenshot and its thumbnail for a project.
// To install the dependencies on Debian/Ubuntu:
// $ sudo apt install imagemagick optipng wkhtmltopdf
const templateFile = "screenshot-page.html";
const temporaryFile = "temp.html";
const slugify = (str: string) =>
str
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/(^-|-$)/g, "");
if (Deno.args.length !== 2) {
console.error("usage: generate-screenshot.ts name css-file");
Deno.exit(1);
}
const screenshotFile = `${slugify(Deno.args[0])}.png`;
const cssFile = Deno.args[1];
try {
const htmlTemplate = await Deno.readTextFile(templateFile);
const css = await Deno.readTextFile(cssFile);
const html = htmlTemplate.replace(/%CSS_HERE%/, css);
await Deno.writeTextFile(temporaryFile, html);
await Deno.run({
cmd: ["wkhtmltoimage", temporaryFile, `screenshot/${screenshotFile}`],
}).status();
await Deno.run({
cmd: [
"convert",
"-resize",
"25%",
"-adaptive-sharpen",
"10",
`screenshot/${screenshotFile}`,
`thumbnail/${screenshotFile}`,
],
}).status();
await Deno.run({
cmd: [
"optipng",
"-o",
"5",
"-strip",
"all",
`screenshot/${screenshotFile}`,
`thumbnail/${screenshotFile}`,
],
}).status();
} catch (err) {
console.error(err);
} finally {
Deno.remove(temporaryFile);
}

43
generate-item.tcl

@ -1,43 +0,0 @@
#! /usr/bin/env tclsh
# Generate the screenshot and its thumbnail for a framework. Print the
# Markdown to add to README.md. To install the dependencies on Debian/Ubuntu:
# $ sudo apt install imagemagick optipng tcl tcllib wkhtmltopdf
package require fileutil
proc [info script] {name css github demo} {
set src screenshot-page.html
set dest temp.html
set filename [slugify $name].png
fileutil::writeFile $dest [regsub %CSS_HERE% [fileutil::cat $src] $css]
run wkhtmltoimage $dest screenshot/$filename
run convert \
-resize 25% \
-adaptive-sharpen 10 \
screenshot/$filename \
thumbnail/$filename
run optipng -o5 -strip all screenshot/$filename thumbnail/$filename
puts ------\n[markup $name $github $demo $filename]
}
proc slugify text {
string trim [regsub -all {[^[:alnum:]]+} [string tolower $text] -] -
}
proc run args {
exec {*}$args >@ stdout 2>@ stderr
}
proc markup {name github demo filename} {
subst -nocommands {### $name
* [Repository](https://github.com/$github) ![GitHub stars](https://img.shields.io/github/stars/$github?style=flat-square) ![GitHub contributors](https://img.shields.io/github/contributors-anon/$github?style=flat-square) ![Last commit](https://img.shields.io/github/last-commit/$github?style=flat-square) ![GitHub open issues](https://img.shields.io/github/issues-raw/$github?style=flat-square) ![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/$github?style=flat-square)
* [Demo]($demo)
[![$filename](thumbnail/$filename)](screenshot/$filename)}
}
[info script] {*}$argv

4
screenshot-page.html

@ -5,7 +5,9 @@
<title>Lorem ipsum dolor sit amet</title> <title>Lorem ipsum dolor sit amet</title>
<!-- <link rel="stylesheet" href="https://unpkg.com/normalize.css@8.0.1/normalize.css" type="text/css"> --> <!-- <link rel="stylesheet" href="https://unpkg.com/normalize.css@8.0.1/normalize.css" type="text/css"> -->
<link rel="stylesheet" href="%CSS_HERE%" /> <style>
%CSS_HERE%
</style>
</head> </head>
<body> <body>

Loading…
Cancel
Save