44render_slides () {
55 local day
66 local escaped_file
7+ local escaped_title
78 local filename
8- local input_file
9+ local input_arg
10+ local input_file_abs
11+ local input_file_rel
12+ local node_max_old_space
13+ local slidev_port
14+ local title
15+
16+ # Remove any surrounding quotes from the argument to avoid breaking realpath
17+ input_arg=${1// \" / }
18+
19+ if ! input_file_abs=$( realpath " $input_arg " ) ; then
20+ error_exit " Could not resolve path for $input_arg "
21+ fi
22+
23+ if [ ! -f " $input_file_abs " ]; then
24+ error_exit " $input_arg doesn't exist"
25+ fi
26+
27+ title=$( awk ' BEGIN{in_frontmatter=0} \
28+ /^---[\r\n]*$/ { if (in_frontmatter) exit; in_frontmatter=1; next } \
29+ in_frontmatter && /^title:[[:space:]]*/ { sub(/^title:[[:space:]]*/,"",$0); print; exit }' " $input_file_abs " )
30+ if [ -z " $title " ]; then
31+ title=" 3mdeb Presentation"
32+ fi
33+
34+ input_file_rel=$( realpath --relative-to " $PWD /slidev-template" " $input_file_abs " )
35+ if [ -z " $input_file_rel " ]; then
36+ error_exit " Couldn't compute relative path for $input_file_abs "
37+ fi
938
10- # Remove any surrounding quotes from the variables
11- input_file=${1// \" / }
12- input_file=" slides/$( realpath --relative-to slidev-template/slides/ " $input_file " ) "
1339 # Derive other necessary variables from the input_file
14- filename=$( basename " $input_file " )
40+ filename=$( basename " $input_file_abs " )
1541 filename=${filename% .* }
1642 day=${filename: 0: 1}
1743 copyright=${COPYRIGHT:- 3mdeb Sp. z o.o. Licensed under the CC BY-SA 4.0}
1844 copyright=${copyright// \" / }
1945
2046 # Escape strings for sed
21- escaped_file=$( printf ' %s\n' " $input_file " | sed -e ' s/[\/&$]/\\&/g' )
47+ escaped_file=$( printf ' %s\n' " $input_file_rel " | sed -e ' s/[\/&$]/\\&/g' )
48+ escaped_title=$( printf ' %s\n' " $title " | sed -e ' s/[\/&$]/\\&/g' )
2249
2350 # Create temporary markdown file using the slide template
24- sed -e " s/<SRC>/$escaped_file /g" -e " s/<DAY>/$day /g" -e " s/<COPYRIGHT>/$copyright /g" \
51+ sed -e " s/<SRC>/$escaped_file /g" -e " s/<DAY>/$day /g" -e " s/<COPYRIGHT>/$copyright /g" -e " s/<TITLE>/ $escaped_title /g " \
2552 slides-template.md > slidev-template/slides.md
2653 cp slidev-template/vite.config.ts .
2754
55+ slidev_port=${SLIDEV_PORT:- 8000}
56+ node_max_old_space=${SLIDEV_NODE_MAX_OLD_SPACE:- 4096}
57+
58+ if command -v python3 > /dev/null 2>&1 ; then
59+ if ! python3 - " $slidev_port " << 'PY '
60+ import socket
61+ import sys
62+
63+ port = int(sys.argv[1])
64+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
65+ s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
66+ try:
67+ s.bind(("0.0.0.0", port))
68+ except OSError:
69+ sys.exit(1)
70+ finally:
71+ s.close()
72+ PY
73+ then
74+ print_error " Port $slidev_port is already in use. Set SLIDEV_PORT to a free port."
75+ exit 1
76+ fi
77+ fi
78+
2879 docker run -it --rm --user $( id -u) :$( id -g) \
2980 -v " $PWD :/repo" \
30- -p 8000:8000 \
81+ -p " $slidev_port " :8000 \
82+ -e NODE_OPTIONS=--max-old-space-size=" $node_max_old_space " \
3183 mcr.microsoft.com/playwright:v1.53.2-noble \
3284 bash -c " cd /repo/slidev-template && npm run dev slides.md -- -o false -p 8000 --remote --force"
3385
@@ -39,7 +91,6 @@ render_slides() {
3991check_dependencies () {
4092 docker run -it --rm --user $( id -u) :$( id -g) \
4193 -v " $PWD :/repo" \
42- -p 8000:8000 \
4394 mcr.microsoft.com/playwright:v1.53.2-noble \
4495 bash -c " cd /repo/slidev-template && npm install"
4596 return $?
@@ -101,21 +152,9 @@ if [ $# -ne 1 ]; then
101152 print_usage_error " Script accepts 1 positional arguments, got $# "
102153fi
103154
104- if [ ! -f " $1 " ]; then
105- error_exit " $1 doesn't exist"
106- fi
107-
108155if ! check_dependencies; then
109156 error_exit " Missing dependencies"
110157fi
111158
112- if [ -L " slidev-template/slides" ]; then
113- unlink slidev-template/slides
114- fi
115-
116- if ! ln -sr . slidev-template/slides; then
117- error_exit " Couldn't create slidev-template/slides symlink"
118- fi
119-
120159# Call the function with the provided YAML file
121160render_slides " $1 "
0 commit comments