-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_html_js.R
More file actions
83 lines (71 loc) · 2.9 KB
/
create_html_js.R
File metadata and controls
83 lines (71 loc) · 2.9 KB
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
# The html pages and the javascript files in js/pages
# are created from template files ; use this script to
# generate the files
library(stringi)
library(readr)
##############################################################################
# A. SETUP
# warning message
msg <- "DO NOT EDIT THIS PAGE DIRECTLY; IT WAS CREATED WITH create_html_js.R"
# load the template files
template_html <- read_lines("templates/template.html")
template_anno <- read_lines("templates/template_anno.js")
template_text <- read_lines("templates/template_text.js")
# these are the names of the pages
page_anno <- c(
"caption", "classify", "depth", "diarization", "embed",
"mask", "object", "segment", "sentiment", "shotboundary",
"stars", "toxic", "transcription", "zeroshot", "metrics",
"color"
)
page_text <- c("citation", "moreinfo", "started")
page_index <- "welcome"
##############################################################################
# B. CREATE HTML PAGES
# 1. Create the welcome page; it is a bit special because it
# lives in the root of the page and therefore needs a different
# path and output location
x <- template_html
x <- stri_replace_all(x, ".", fixed = "{{PATH}}")
x <- stri_replace_all(x, "welcome", fixed = "{{PAGE}}")
x <- stri_replace_all(x, msg, fixed = "{{MESSAGE}}")
write_lines(x, "index.html")
# 2. Create the other html pages; they are all the same format
page_html <- c(page_text, page_anno)
for (i in seq_along(page_html)) {
pg <- page_html[i]
x <- template_html
x <- stri_replace_all(x, "../..", fixed = "{{PATH}}")
x <- stri_replace_all(x, pg, fixed = "{{PAGE}}")
x <- stri_replace_all(x, msg, fixed = "{{MESSAGE}}")
write_lines(x, file.path("pages", pg, "index.html"))
}
##############################################################################
# C. CREATE JS FILES
# 1. create the welcome-page javascript file
x <- template_text
x <- stri_replace_all(x, ".", fixed = "{{PATH}}")
x <- stri_replace_all(x, "welcome", fixed = "{{PAGE}}")
x <- stri_replace_all(x, msg, fixed = "{{MESSAGE}}")
x <- stri_replace_all(x, "true", fixed = "{{ISROOT}}")
write_lines(x, file.path("js", "pages", paste0("welcome", ".js")))
# 2. create the other text-based javascript files
for (i in seq_along(page_text)) {
pg <- page_text[i]
x <- template_text
x <- stri_replace_all(x, "../..", fixed = "{{PATH}}")
x <- stri_replace_all(x, pg, fixed = "{{PAGE}}")
x <- stri_replace_all(x, msg, fixed = "{{MESSAGE}}")
x <- stri_replace_all(x, "false", fixed = "{{ISROOT}}")
write_lines(x, file.path("js", "pages", paste0(pg, ".js")))
}
# 3. create the annotation javascript files
for (i in seq_along(page_anno)) {
pg <- page_anno[i]
pgcap <- stri_trans_totitle(pg)
x <- template_anno
x <- stri_replace_all(x, pg, fixed = "{{PAGE}}")
x <- stri_replace_all(x, pgcap, fixed = "{{PAGECAP}}")
x <- stri_replace_all(x, msg, fixed = "{{MESSAGE}}")
write_lines(x, file.path("js", "pages", paste0(pg, ".js")))
}