Skip to content

Instantly share code, notes, and snippets.

@esafwan
Last active April 19, 2024 21:06
Show Gist options
  • Save esafwan/fb39e5230aa544ffe6f24d56832fd5c7 to your computer and use it in GitHub Desktop.
Save esafwan/fb39e5230aa544ffe6f24d56832fd5c7 to your computer and use it in GitHub Desktop.
Typst catlog
#let img(image_path, img_width: auto, img_height: auto, img_alt: none, img_fit: "cover") = [
#image(image_path, width: img_width, height: img_height, alt: img_alt, fit: img_fit)
]
#let fig(image_path, img_width: auto, img_height: auto, img_alt: none, img_fit: "cover", img_caption: none) = [
#figure(
image(image_path, width: img_width, height: img_height, alt: img_alt, fit: img_fit),
caption: [
img_caption
]
)
]
//Set page to A4 Size and margin auto
#set page(paper: "a4", margin: 40pt)
#import "component/img.typ": img
#let products = json("data/products.json")
#let cols = 4 //no of cols
#grid(
columns: (1fr,)* cols ,
// Equal fraction of available width for each column
rows: (auto),
// 1cm height for each row
gutter: 1pt,
// Space between cells
stroke: black.transparentize(99%),
align: center + horizon,
..products.map(product => [
#img("../img/"+product.image, img_width: auto, img_height: 100pt, img_fit: "contain" )
== #product.title \
#product.price \ \
])
)
[
{"image": "1.png", "title": "Comfortable Chair", "price": "149.99"},
{"image": "2.png", "title": "Sturdy Table", "price": "249.99"},
{"image": "3.png", "title": "Bright Lamp", "price": "89.99"},
{"image": "4.png", "title": "Interesting Book", "price": "5.99"},
{"image": "1.png", "title": "Comfortable Chair", "price": "149.99"},
{"image": "2.png", "title": "Sturdy Table", "price": "249.99"},
{"image": "3.png", "title": "Bright Lamp", "price": "89.99"},
{"image": "4.png", "title": "Interesting Book", "price": "5.99"},
{"image": "1.png", "title": "Comfortable Chair", "price": "149.99"},
{"image": "2.png", "title": "Sturdy Table", "price": "249.99"},
{"image": "3.png", "title": "Bright Lamp", "price": "89.99"},
{"image": "4.png", "title": "Interesting Book", "price": "5.99"}
]
@esafwan
Copy link
Author

esafwan commented Apr 19, 2024

Screenshot 2024-04-20 at 2 32 00 AM image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment