Summary Files Commits Branches @commit @diff @stats
path: root / generate-hooks / create-presentation.awk
blob: ae7fedf6a257fa8715197bea715947438d16d9c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# A presentation is just a markdown file, with some added ftags for formatting into a presentation layout.
# This means all presentations will change how they look with changes to the main styles.css. It also means
# that they follow the light/dark mode setting.
# Each slide is the size of a horizontal A4 piece of paper. This makes it easy to print (and there is a dedicated
# print button).
# The whole system is based on flexboxes. The only real way to control how items are aligned is via a row and column
# directed flexboxes. This isn't the most efficient, but it's fine. And if there are performance issues, the
# presentation can always be "printed" to a PDF and consumed that way.

# Currently you can have normal paragraphs and heading around a presentation, and those won't be printed out.
# But you can have only ONE presentation per page!!!
# All ftags that have a closing tag, and &&presentation, need one line above and below them (but you don't
# need the first and last line of file to be empty).

# &&presentation    Required. Adds the control panel and JavaScript script. Must be the very first one!
# &&slide           Starts a slide. Slides are the main pages that hold content and are used for navigation.
# &&/slide          Ends (the last started) slide.
# &&flexer          An empty container with flex: 1. Use it for spacing out stuff.
# &&centered        Aligns text to the center.
# &&/centered       Ends (the last started) centered text.
# &&fow             Flexbox, with flex-direction row.
# &&/fow            Ends (the last started) fow.
# &&fol             Flexbox, with flex-direction column.
# &&/fol            Ends (the last started) fol.

BEGIN {
	if (substr(FILENAME, "talks") == 0) exit

	# Exceptions to the normal format
	names[ 1] = "presentation"
	ended[ 1] = 0
	names[ 2] = "/font" # all font ftags can be closed with a &&/font
	ended[ 2] = 0

	names[ 3] = "slide"
	ended[ 3] = 1
	names[ 4] = "centered"
	ended[ 4] = 1
	names[ 5] = "flexer"
	ended[ 5] = 2
	names[ 6] = "fow"
	ended[ 6] = 1
	names[ 7] = "fol"
	ended[ 7] = 1
	names[ 8] = "font18"
	ended[ 8] = 0
	names[ 9] = "font20"
	ended[ 9] = 0
	names[10] = "font27"
	ended[10] = 0
	names[11] = "font30"
	ended[11] = 0
	names[12] = "font35"
	ended[12] = 0
	names[13] = "fright"
	ended[13] = 1

	pres = ORS \
"<nav id=\"presentCont\">" ORS \
"	<img id=\"prevSlideBtn\" class=\"unzoomable btn setting-btn icon nodisplay\" src=\"/img/arrow-left-tabler.svg\" alt=\"Previous\">" ORS \
"	<img id=\"nextSlideBtn\" class=\"unzoomable btn setting-btn icon nodisplay\" src=\"/img/arrow-right-tabler.svg\" alt=\"Next\">" ORS \
"	<img id=\"presentBtn\" class=\"unzoomable btn setting-btn icon\" src=\"/img/presentation-tabler.svg\" alt=\"Present\">" ORS \
"	<img id=\"printBtn\" class=\"unzoomable btn setting-btn icon\" src=\"/img/printer-tabler.svg\" alt=\"Print\">" ORS \
"		</nav>" ORS \
"		<script type=\"text/javascript\" src=\"/scripts/presentation.js\" integrity=\"sha512-79MwfB0EQJMdVjVnd3PA0Cn9fo4JaMUmNuyZNEGSbaMEGcqdE8sWWAbMLheaoptDyb/KuYgNw0pKwvR5Dw+lJw==\" crossorigin=\"anonymous\"></script>"

	pat[1] = "&#38;&#38;presentation"
	rep[1] = pres
	pat[2] = "&#38;&#38;&#47;font"
	rep[2] = "</div>"

	for (i = 3; i <= length(names); i++) {
		pat[i] = "&#38;&#38;" names[i]
		rep[i] = "<div class=\"" names[i] "\">"

		if (ended[i] == 1) {
			cpat[i] = "&#38;&#38;&#47;" names[i]
			crep[i] = "</div>"
		}
		else if (ended[i] == 2) {
			rep[i] = rep[i] "</div>"
		}
	}
}

function substitute(ind) {
	gsub(/(<p>|<\/p>)/, "")
	gsub(pat[ind], rep[ind])
	if (ended[ind] == 1)
		gsub(cpat[ind], crep[ind])
}

/^[ \t]*(<p>|)&#38;&#38;/ {
	for (i = 1; i <= length(names); i++) {
		if (index($0, names[i]) != 0)
			substitute(i)
	}
}

{
	print
}