168 lines
3.4 KiB
JavaScript
168 lines
3.4 KiB
JavaScript
let steps = {
|
|
faculty: {
|
|
title: "Pro kterou fakultu budete svou práci tvořit?",
|
|
layout: faculty_layout,
|
|
result: {
|
|
name: ""
|
|
}
|
|
},
|
|
thesis_type: {
|
|
title: "Jakou práci budete tvořit?",
|
|
layout: thesis_layout,
|
|
result: {
|
|
type: ""
|
|
}
|
|
},
|
|
author_info: {
|
|
title: "Vaše údaje",
|
|
layout: author_info_layout,
|
|
result: {
|
|
name: "",
|
|
pronouns: ""
|
|
}
|
|
},
|
|
collaborators: {
|
|
title: "Vedoucí práce",
|
|
layout: collaborators_layout,
|
|
result: {
|
|
has_supervisor: true,
|
|
supervisor_name: "",
|
|
has_consultant: false,
|
|
consultant_name: ""
|
|
}
|
|
},
|
|
}
|
|
|
|
const faculties = {
|
|
"fs": {
|
|
name: "Fakulta strojní"
|
|
},
|
|
"ft": {
|
|
name: "Fakulta textilní"
|
|
},
|
|
"fp": {
|
|
name: "Fakulta přirodovědně-humanitní a pedagogická"
|
|
},
|
|
"ef": {
|
|
name: "Ekonomická fakulta"
|
|
},
|
|
"fua": {
|
|
name: "Fakulta umění a architektury"
|
|
},
|
|
"fm": {
|
|
name: "Fakulta mechatroniky, informatiky a mezioborových studií"
|
|
},
|
|
"fzs": {
|
|
name: "Fakulta zdravotnických studií"
|
|
},
|
|
"cxi": {
|
|
name: "Ústav pro nanomateriály, pokročilé technologie a inovace"
|
|
}
|
|
}
|
|
|
|
const theses = {
|
|
"bp": {
|
|
name: "Bakalářská práce"
|
|
},
|
|
"dp": {
|
|
name: "Diplomová práce"
|
|
},
|
|
"dis": {
|
|
name: "Disertační práce"
|
|
},
|
|
"hab": {
|
|
name: "Habilitační práce"
|
|
},
|
|
"teze": {
|
|
name: "Teze disertační práce"
|
|
},
|
|
"autoref": {
|
|
name: "Autoreferát disertační práce"
|
|
},
|
|
"proj": {
|
|
name: "Projekt"
|
|
},
|
|
"sp": {
|
|
name: "Semestrální práce"
|
|
}
|
|
}
|
|
|
|
const pronounss = {
|
|
"masculine": {
|
|
name: "Mužský rod"
|
|
},
|
|
"feminine": {
|
|
name: "Ženský rod"
|
|
},
|
|
"we": {
|
|
name: "Množné číslo"
|
|
}
|
|
}
|
|
|
|
const typst_header = `#import "template/template.typ": *
|
|
|
|
#show: tultemplate2.with(
|
|
faculty: "{faculty.name}",
|
|
document: "{thesis_type.type}",
|
|
title: (cs: "Návod na použití Typst TUL šablony"),
|
|
author: "{author_info.name}",
|
|
author_pronouns: "{author_info.pronouns}",
|
|
<collaborators.has_supervisor: supervisor: "{collaborators.supervisor_name}",
|
|
><collaborators.has_consultant: consultant: "{collaborators.consultant_name}",
|
|
> citations: "citations.bib",
|
|
assignment: "zadani.pdf"
|
|
)
|
|
|
|
= Nadpis
|
|
|
|
skibidi
|
|
`;
|
|
|
|
async function generate_zip() {
|
|
let assets_zip = await fetch("template.zip");
|
|
let out_zip = await new JSZip().loadAsync(await assets_zip.blob());
|
|
|
|
let out = typst_header;
|
|
|
|
for(const step_key in steps) {
|
|
console.log(step_key);
|
|
|
|
for(const key in steps[step_key].result) {
|
|
console.log("- " + key);
|
|
|
|
const search_condition = "<" + step_key + "." + key + ":";
|
|
const condition_pos = out.search(search_condition);
|
|
|
|
if(condition_pos >= 0) {
|
|
const condition_end_pos = out.slice(condition_pos).search(">");
|
|
|
|
if(condition_end_pos >= 0) {
|
|
const head = out.slice(0, condition_pos);
|
|
const meat = steps[step_key].result[key] ? out.slice(condition_pos + search_condition.length, condition_pos + condition_end_pos) : "";
|
|
const tail = out.slice(condition_pos + condition_end_pos + 1);
|
|
|
|
out = head + meat + tail;
|
|
}
|
|
}
|
|
|
|
const search_replacement = "{" + step_key + "." + key + "}";
|
|
const replacement_pos = out.search(search_replacement);
|
|
|
|
if(replacement_pos >= 0) {
|
|
const head = out.slice(0, replacement_pos);
|
|
const meat = steps[step_key].result[key];
|
|
const tail = out.slice(replacement_pos + search_replacement.length);
|
|
|
|
out = head + meat + tail;
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(out);
|
|
|
|
out_zip.file("thesis.typ", out);
|
|
|
|
return await out_zip.generateAsync({ type: "blob" });
|
|
}
|
|
|