-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(gallery): use freeze for gallery images (#322)
- Loading branch information
Showing
11 changed files
with
132 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
Glamour | ||
======= | ||
|
||
A casual introduction. 你好世界! | ||
|
||
## Let’s talk about artichokes | ||
|
||
The _artichoke_ is mentioned as a garden plant in the 8th century BC by Homer | ||
**and** Hesiod. The naturally occurring variant of the artichoke, the cardoon, | ||
which is native to the Mediterranean area, also has records of use as a food | ||
among the ancient Greeks and Romans. Pliny the Elder mentioned growing of | ||
_carduus_ in Carthage and Cordoba. | ||
|
||
> He holds him with a skinny hand, | ||
> ‘There was a ship,’ quoth he. | ||
> ‘Hold off! unhand me, grey-beard loon!’ | ||
> An artichoke, dropt he. | ||
--Samuel Taylor Coleridge, [The Rime of the Ancient Mariner][rime] | ||
|
||
[rime]: https://poetryfoundation.org/poems/43997/ | ||
|
||
## Other foods worth mentioning | ||
|
||
1. Carrots | ||
1. Celery | ||
1. Tacos | ||
* Soft | ||
* Hard | ||
1. Cucumber | ||
|
||
## Things to eat today | ||
|
||
* [x] Carrots | ||
* [x] Ramen | ||
* [ ] Currywurst | ||
|
||
### Power levels of the aforementioned foods | ||
|
||
| Name | Power | Comment | | ||
| --- | --- | --- | | ||
| Carrots | 9001 | It’s over 9000?! | | ||
| Ramen | 9002 | Also over 9000?! | | ||
| Currywurst | 10000 | What?! | | ||
|
||
## Currying Artichokes | ||
|
||
Here’s a bit of code in [Haskell](https://haskell.org), because we are fancy. | ||
Remember that to compile Haskell you’ll need `ghc`. | ||
|
||
```haskell | ||
module Main where | ||
|
||
import Data.Function ( (&) ) | ||
import Data.List ( intercalculate ) | ||
|
||
hello :: String -> String | ||
hello s = | ||
"Hello, " ++ s ++ "." | ||
|
||
main :: IO () | ||
main = | ||
map hello [ "artichoke", "alcachofa" ] & intercalculate "\n" & putStrLn | ||
``` | ||
|
||
*** | ||
|
||
_Alcachofa_, if you were wondering, is artichoke in Spanish. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/charmbracelet/glamour" | ||
"github.com/muesli/termenv" | ||
) | ||
|
||
//go:embed artichokes.md | ||
var f embed.FS | ||
|
||
func main() { | ||
// Provide a style by name (optional) | ||
var style string | ||
if len(os.Args) < 2 { | ||
// check env, if unset then use default style | ||
style = os.Getenv("GLAMOUR_STYLE") | ||
} else { | ||
style = os.Args[1] | ||
} | ||
|
||
// Let's learn a 'lil something about artichokes... | ||
b, err := f.ReadFile("artichokes.md") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
r, err := glamour.NewTermRenderer( | ||
glamour.WithStandardStyle(style), | ||
glamour.WithColorProfile(termenv.TrueColor), | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
md, err := r.RenderBytes(b) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Fprintf(os.Stdout, "%s\n", md) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
#!/bin/bash | ||
|
||
for style in ./styles/*.json; do | ||
echo "Generating screenshot for ${style}" | ||
filename="`basename -s .json ${style}`.png" | ||
if ! command -v freeze &> /dev/null; then | ||
echo "freeze not found. Please install freeze to capture images." | ||
echo "https://github.com/charmbracelet/freeze/" | ||
exit 1 | ||
fi | ||
|
||
light="" | ||
if [[ $style == *"light"* ]]; then | ||
light="-l" | ||
fi | ||
defaultStyles=("ascii" "auto" "dark" "dracula" "light" "notty" "pink") | ||
|
||
for style in "${defaultStyles[@]}"; do | ||
echo "Generating screenshot for ${style}" | ||
# take screenshot | ||
./termshot ${light} -o ./styles/gallery/ -f "$filename" glow -s ${style} | ||
|
||
# add border | ||
convert -bordercolor black -border 16x16 "./styles/gallery/$filename" "./styles/gallery/$filename" | ||
if [[ $style == *"light"* ]]; then | ||
# Provide a light background to images | ||
freeze -x "go run ./examples/artichokes ${style}" -b "#FAFAFA" -o "./styles/gallery/${style}.png" | ||
else | ||
freeze -x "go run ./examples/artichokes ${style}" -o "./styles/gallery/${style}.png" | ||
fi | ||
|
||
# optimize filesize | ||
pngcrush -ow "./styles/gallery/$filename" | ||
pngcrush -ow "./styles/gallery/$style.png" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.