Skip to content

Commit b8e4194

Browse files
authored
Document frontmatter (#46)
1 parent 0da9818 commit b8e4194

File tree

4 files changed

+150
-40
lines changed

4 files changed

+150
-40
lines changed

src/assets/img/compress_pngs.sh

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22

33
# PNG Compression Script
4-
# Compresses all PNG files in the current directory using pngquant
4+
# Compresses PNG files using pngquant
5+
# Can compress all PNGs in current directory or a specific file
56
# Shows before/after sizes and calculates total savings
67
# Skips files that are already compressed (8-bit or limited palette)
78

@@ -28,34 +29,87 @@ if ! command -v identify &> /dev/null; then
2829
exit 1
2930
fi
3031

31-
# Check if there are PNG files in the current directory
32-
if ! ls *.png >/dev/null 2>&1; then
33-
echo -e "${RED}No PNG files found in the current directory.${NC}"
34-
exit 1
35-
fi
32+
# Parse arguments
33+
FORCE=false
34+
TARGET_FILE=""
35+
36+
while [[ $# -gt 0 ]]; do
37+
case $1 in
38+
--force)
39+
FORCE=true
40+
shift
41+
;;
42+
--help)
43+
echo -e "${BLUE}Usage:${NC}"
44+
echo -e " ./compress_pngs.sh [OPTIONS] [FILENAME]"
45+
echo -e ""
46+
echo -e "${BLUE}Options:${NC}"
47+
echo -e " --force Force compress all files (not recommended)"
48+
echo -e " --help Show this help"
49+
echo -e ""
50+
echo -e "${BLUE}Examples:${NC}"
51+
echo -e " ./compress_pngs.sh # Compress all PNGs in current directory"
52+
echo -e " ./compress_pngs.sh image.png # Compress only image.png"
53+
echo -e " ./compress_pngs.sh --force # Force compress all files"
54+
exit 0
55+
;;
56+
-*)
57+
echo -e "${RED}Unknown option: $1${NC}"
58+
echo "Use --help for usage information"
59+
exit 1
60+
;;
61+
*)
62+
if [[ -z "$TARGET_FILE" ]]; then
63+
TARGET_FILE="$1"
64+
else
65+
echo -e "${RED}Error: Only one filename can be specified${NC}"
66+
exit 1
67+
fi
68+
shift
69+
;;
70+
esac
71+
done
3672

37-
echo -e "${BLUE}🖼️ PNG Compression Script${NC}"
38-
echo -e "${BLUE}=========================${NC}\n"
73+
# Determine which files to process
74+
PNG_FILES=()
75+
if [[ -n "$TARGET_FILE" ]]; then
76+
# Single file specified
77+
if [[ ! -f "$TARGET_FILE" ]]; then
78+
echo -e "${RED}Error: File '$TARGET_FILE' does not exist.${NC}"
79+
exit 1
80+
fi
81+
82+
# Check if it's a PNG file (case insensitive)
83+
if [[ ! "$TARGET_FILE" =~ \.[Pp][Nn][Gg]$ ]]; then
84+
echo -e "${RED}Error: '$TARGET_FILE' is not a PNG file.${NC}"
85+
exit 1
86+
fi
87+
88+
PNG_FILES=("$TARGET_FILE")
89+
echo -e "${BLUE}🖼️ PNG Compression Script - Single File Mode${NC}"
90+
echo -e "${BLUE}=============================================${NC}\n"
91+
else
92+
# Process all PNG files in current directory
93+
if ! ls *.png >/dev/null 2>&1; then
94+
echo -e "${RED}No PNG files found in the current directory.${NC}"
95+
exit 1
96+
fi
97+
98+
for file in *.png; do
99+
if [[ -f "$file" ]]; then
100+
PNG_FILES+=("$file")
101+
fi
102+
done
103+
104+
echo -e "${BLUE}🖼️ PNG Compression Script - Directory Mode${NC}"
105+
echo -e "${BLUE}===========================================${NC}\n"
106+
fi
39107

40108
# Quality setting (can be modified)
41109
QUALITY="65-80"
42110

43-
# Option to create backups
44-
BACKUP=false
45-
FORCE=false
46-
if [[ "$1" == "--backup" ]]; then
47-
BACKUP=true
48-
echo -e "${YELLOW}Creating backups of original files...${NC}"
49-
elif [[ "$1" == "--force" ]]; then
50-
FORCE=true
111+
if [[ "$FORCE" == true ]]; then
51112
echo -e "${YELLOW}Force mode: will compress all files regardless of current state${NC}"
52-
elif [[ "$1" == "--help" ]]; then
53-
echo -e "${BLUE}Usage:${NC}"
54-
echo -e " ./compress_pngs.sh # Normal compression (skips already compressed)"
55-
echo -e " ./compress_pngs.sh --backup # Create backups before compression"
56-
echo -e " ./compress_pngs.sh --force # Force compress all files (not recommended)"
57-
echo -e " ./compress_pngs.sh --help # Show this help"
58-
exit 0
59113
fi
60114

61115
# Function to check if PNG is already compressed (8-bit or limited colors)
@@ -83,7 +137,7 @@ TO_COMPRESS=()
83137
ALREADY_COMPRESSED=()
84138
FAILED_ANALYSIS=()
85139

86-
for file in *.png; do
140+
for file in "${PNG_FILES[@]}"; do
87141
if [[ -f "$file" ]]; then
88142
if [[ "$FORCE" == true ]]; then
89143
TO_COMPRESS+=("$file")
@@ -122,13 +176,6 @@ fi
122176

123177
echo ""
124178

125-
# Create backup if requested
126-
if [[ "$BACKUP" == true ]]; then
127-
mkdir -p originals
128-
cp "${TO_COMPRESS[@]}" originals/
129-
echo -e "${GREEN}✅ Backups created in 'originals' folder${NC}\n"
130-
fi
131-
132179
# Compress each PNG file that needs compression
133180
echo -e "${BLUE}🔄 Compressing files...${NC}"
134181
COMPRESSED_COUNT=0
@@ -173,10 +220,6 @@ echo -e "Size after: ${TOTAL_AFTER}"
173220
echo -e "Space saved: ${SAVINGS_KB}KB"
174221
echo -e "${GREEN}Reduction: ${SAVINGS_PERCENT}%${NC}"
175222

176-
if [[ "$BACKUP" == true ]]; then
177-
echo -e "${YELLOW}\n💡 Original files are backed up in 'originals' folder${NC}"
178-
fi
179-
180223
echo -e "\n${BLUE}ℹ️ Note: This uses lossy compression (reduces colors to ~256)${NC}"
181224
echo -e "${BLUE} Quality setting used: ${QUALITY}${NC}"
182225
echo -e "${BLUE} Skipped files with ≤8-bit depth or ≤256 colors${NC}"
66.2 KB
Loading

src/en/docs/export.jlmd

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,4 @@ After writing your Pluto notebook, you have a couple options to **export** your
1818
> Press the **Share** button in the top right.
1919
>
2020
> <img src="$(root_url)/assets/img/Share button screenshot.png" alt="Screenshot of the Share button" width="1532" height="282">
21-
>
22-
> ### Step 3
23-
> Choose "Notebook file".
24-
>
25-
> <img src="$(root_url)/assets/img/Export options screenshot.png" alt="Screenshot of the export options" width="1804" height="472">
2621

src/en/docs/frontmatter.jlmd

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: "📰 Frontmatter"
3+
description: "How to use frontmatter in Pluto.jl notebooks."
4+
tags: ["docs", "publishing", "frontmatter", "yaml", "markdown", "file", "export", "share", "web"]
5+
layout: "md.jlmd"
6+
order: 7
7+
---
8+
9+
# Frontmatter <span id="frontmatter"></span>
10+
11+
Frontmatter is a way to add metadata to a Pluto.jl notebook, such as the title, description, authors, cover image, license, date and more. This data is used when **sharing notebooks online**, using [Pluto HTML exports](../export-html/), [`PlutoUI.NotebookCard`](https://featured.plutojl.org/basic/plutoui.jl#NotebookCard), [PlutoSliderServer](https://github.com/JuliaPluto/PlutoSliderServer.jl), [PlutoPages](https://github.com/JuliaPluto/PlutoPages.jl) or [pluto.land](https://pluto.land).
12+
13+
For example, the [featured notebooks](../featured-notebooks/) use frontmatter. When you see the list of all featured notebooks, notice how they all have a title, description, cover image and authors. And they are
14+
15+
16+
## The frontmatter GUI
17+
When editing a Pluto notebook, you can open the frontmatter editor by clicking the "Share button" in the top right.
18+
19+
<img src="$(root_url)/assets/img/Share button screenshot.png" alt="Screenshot of the Share button" width="1532" height="282">
20+
21+
In the share menu, click the <img src="https://cdn.jsdelivr.net/gh/ionic-team/ionicons@5.5.1/src/svg/newspaper-outline.svg" alt="📰" width=17px style="filter: var(--image-filters);"> icon to open the frontmatter editor.
22+
23+
24+
<blockquote style="max-height: 300px; overflow-y: auto;">
25+
<p>Here is a screenshot of the frontmatter editor. Scroll down to see more.</p>
26+
27+
<img src="$(root_url)/assets/img/frontmatter heatmap screenshot.png" alt="Screenshot of the frontmatter editor" width="854" height="1570">
28+
</blockquote>
29+
30+
In this editor, you can edit fields and add new fields. You are free to enter any data that you want (which you might want to [use](#Pluto.frontmatter) in your custom scripts), but some frontmatter entries have special meaning in the Pluto ecosystem.
31+
32+
### Special frontmatter entries
33+
The following keys have special meaning:
34+
- **`title`** – the title of the document. When not used, the notebook filename is used as title. This is used in Pluto.jl HTML exports as the `<title>` tag.
35+
- **`description`** – the description of the document. This is used in Pluto.jl HTML exports as the `<meta name="description" content="...">` tag.
36+
- **`image`** – the URL of the cover image of the document.
37+
- **`date`** – the date of the document.
38+
- **`license`** – the license of the document.
39+
- **`tags`** – a vector of tags for the document, used by the PlutoPages.jl sidebar and search, and PlutoSliderServer.jl.
40+
- **`layout`** – the PlutoPages.jl layout file of the document.
41+
- **`order`** – the order of the document within its category.
42+
43+
### Open Graph (OG) tags
44+
The following keys are used as [Open Graph (OG) tags](https://ogp.me/) in Pluto.jl HTML exports (using `<meta property="og:...">`):
45+
46+
`title`, `type`, `description`, `image`, `article:tag`, `url`, `audio`, `video`, `site_name`, `locale`, `locale:alternate`, `determiner`.
47+
48+
Setting these values helps with sharing notebooks on social media and search engine optimization.
49+
50+
### The `author` field
51+
There is also a vector `author` that is used to provide the authors of the notebook. The following fields have special meaning in the Pluto ecosystem:
52+
- **`name`** – the name of the author.
53+
- **`url`** – the URL of the author's website. If this is a github user/organization URL, the author's avatar will be shown in the notebook.
54+
- **`image`** - the URL of the author's avatar. This is not needed if the `url` is a github URL.
55+
56+
57+
## PlutoPages.jl
58+
If you are using [PlutoPages.jl](https://github.com/JuliaPluto/PlutoPages.jl) to write your website, you should at least set the following frontmatter entries for every page: `layout` and `tags`. (`layout` is the name of the layout file in the `src/_includes/` directory.)
59+
60+
61+
## Featured notebooks
62+
If you are writing a featured notebook, check out other featured notebook files to see which frontmatter entries are required.
63+
64+
65+
## <span id="Pluto.frontmatter">Accessing frontmatter from Julia</span>
66+
If you are writing a script to process Pluto notebooks, you can access the frontmatter data using the **`Pluto.frontmatter`** function. This function takes a notebook path as an argument, and returns a `Dict` with the frontmatter data.
67+
68+
```julia
69+
path = "/path/to/notebook.jl"
70+
frontmatter = Pluto.frontmatter(path)
71+
@info "Written by" frontmatter["author"]
72+
```

0 commit comments

Comments
 (0)