Skip to content

Commit

Permalink
refactor(gallery): use freeze for gallery images (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni authored Aug 2, 2024
1 parent dad25dc commit 1fcce6f
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 16 deletions.
68 changes: 68 additions & 0 deletions examples/artichokes/artichokes.md
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.
45 changes: 45 additions & 0 deletions examples/artichokes/main.go
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)
}
27 changes: 15 additions & 12 deletions gallery.sh
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
8 changes: 4 additions & 4 deletions styles/gallery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

## Dark

![Glamour Dark Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/dark.png)
![Glamour Dark Style](dark.png)

## Light

![Glamour Light Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/light.png)
![Glamour Light Style](light.png)

## NoTTY

Pronounced _naughty_.

![Glamour NoTTY Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/notty.png)
![Glamour NoTTY Style](notty.png)

## Dracula

![Dracula Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/dracula.png)
![Dracula Style](dracula.png)
Binary file added styles/gallery/ascii.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styles/gallery/auto.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified styles/gallery/dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified styles/gallery/dracula.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified styles/gallery/light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified styles/gallery/notty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styles/gallery/pink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1fcce6f

Please sign in to comment.