319 lines
6.6 KiB
JavaScript
319 lines
6.6 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: ""
|
|
}
|
|
},
|
|
language: {
|
|
title: "V jakém jazyce budete práci tvořit?",
|
|
layout: language_layout,
|
|
result: {
|
|
lang: "cs"
|
|
},
|
|
finalize: (result) => {
|
|
result.is_cs = result.lang === "cs";
|
|
result.is_en = result.lang === "en";
|
|
}
|
|
},
|
|
thesis_title: {
|
|
title: "Jak se bude práce jmenovat?",
|
|
layout: thesis_title_layout,
|
|
result: {
|
|
cs: "",
|
|
en: ""
|
|
},
|
|
finalize: (result) => {
|
|
if(result.cs === "") {
|
|
result.cs = "SEM DOPLŇTE ČESKÝ NÁZEV PRÁCE";
|
|
}
|
|
|
|
if(result.en === "") {
|
|
result.en = "SEM DOPLŇTE ANGLICKÝ NÁZEV PRÁCE";
|
|
}
|
|
}
|
|
},
|
|
author_info: {
|
|
title: "Vaše údaje",
|
|
layout: author_info_layout,
|
|
result: {
|
|
name: "",
|
|
pronouns: ""
|
|
},
|
|
finalize: (result) => {
|
|
if(result.name === "") {
|
|
result.name = "SEM DOPLŇTE VAŠE JMÉNO";
|
|
}
|
|
}
|
|
},
|
|
programme: {
|
|
title: "Který program studujete?",
|
|
layout: programme_layout,
|
|
result: {
|
|
faculty: "", // used for checking whether to clear
|
|
idx: -1 // -1 = none, 0+ = index into programmes[faculty]
|
|
},
|
|
finalize: (result) => {
|
|
if(result.idx == -1) {
|
|
result.has_programme = false;
|
|
return
|
|
}
|
|
|
|
let programme = programmes[steps.faculty.result.name][result.idx];
|
|
|
|
result.has_programme = true;
|
|
result.programme = programme.code + " " + (
|
|
steps.language.result.lang == "cs" ?
|
|
programme.cs_name :
|
|
programme.en_name
|
|
);
|
|
}
|
|
},
|
|
collaborators: {
|
|
title: "Vedoucí práce",
|
|
layout: collaborators_layout,
|
|
result: {
|
|
has_supervisor: true,
|
|
supervisor_name: "",
|
|
has_consultant: false,
|
|
consultant_name: ""
|
|
},
|
|
finalize: (result) => {
|
|
if(result.supervisor_name === "") {
|
|
result.supervisor_name = "SEM DOPLŇTE JMÉNO VEDOUCÍHO PRÁCE";
|
|
}
|
|
|
|
if(result.consultant_name === "") {
|
|
result.consultant_name = "SEM DOPLŇTE JMÉNO KONZULTANTA PRÁCE";
|
|
}
|
|
}
|
|
},
|
|
assignment: {
|
|
title: "Jak vložit zadání?",
|
|
layout: assignment_layout,
|
|
result: {
|
|
format: "empty"
|
|
},
|
|
finalize: (result) => {
|
|
result.include_pdf = result.format === "external";
|
|
}
|
|
},
|
|
finishing_touches: {
|
|
title: "Závěrečné detaily",
|
|
layout: finishing_touches_layout,
|
|
result: {
|
|
has_keywords: true,
|
|
has_acknowledgement: true
|
|
}
|
|
}
|
|
}
|
|
|
|
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 languages = {
|
|
"cs": {
|
|
name: "Čeština"
|
|
},
|
|
"en": {
|
|
name: "Angličtina"
|
|
}
|
|
}
|
|
|
|
const pronouns_cs = {
|
|
"masculine": {
|
|
name: "Mužský rod"
|
|
},
|
|
"feminine": {
|
|
name: "Ženský rod"
|
|
},
|
|
"we": {
|
|
name: "Množné číslo"
|
|
}
|
|
}
|
|
|
|
const pronouns_en = {
|
|
"me": {
|
|
name: "Jednotné čislo"
|
|
},
|
|
"we": {
|
|
name: "Množné číslo"
|
|
}
|
|
}
|
|
|
|
const assignment_formats = {
|
|
"empty": {
|
|
name: "Vložit do dokumentu prázdnou stránku.\nTuto stránku poté nahradíte podepsaným zadáním před vazbou dokumentu."
|
|
},
|
|
"external": {
|
|
name: "Vložit do dokumentu zadání ve formě PDF."
|
|
}
|
|
}
|
|
|
|
const typst_header = `#import "template/template.typ": *
|
|
|
|
#show: tultemplate2.with(
|
|
faculty: "{faculty.name}",
|
|
document: "{thesis_type.type}",
|
|
lang: "{language.lang}",
|
|
title: (cs: "{thesis_title.cs}", en: "{thesis_title.en}"),
|
|
<finishing_touches.has_keywords: keywords: (
|
|
cs: ("DOPLŇTE", "SEM", "KLÍČOVÁ", "SLOVA"),
|
|
en: ("INSERT", "KEYWORDS", "HERE")
|
|
)
|
|
><finishing_touches.has_acknowledgement: acknowledgement: (
|
|
<language.is_cs:cs: "
|
|
Rád bych poděkoval všem, kteří přispěli ke vzniku tohoto dílka.
|
|
"><language.is_en:en: "
|
|
I would like to acknowledge everyone who contributed to the creation of this fine piece of work.
|
|
">
|
|
)
|
|
> abstract: (
|
|
cs: "
|
|
Sem vyplňte abstrakt své práce v češtině.
|
|
",
|
|
en: "
|
|
Insert the abstract of your theses in English here.
|
|
"
|
|
),
|
|
author: "{author_info.name}",
|
|
author_pronouns: "{author_info.pronouns}",
|
|
<collaborators.has_supervisor: supervisor: "{collaborators.supervisor_name}",
|
|
><collaborators.has_consultant: consultant: "{collaborators.consultant_name}",
|
|
><programme.has_programme: programme: ({language.lang}: "{programme.programme}"}),
|
|
><assignment.include_pdf: assignment: "assignment.pdf",
|
|
> citations: "citations.bib"
|
|
)
|
|
|
|
= Nadpis
|
|
|
|
skibidi
|
|
`;
|
|
|
|
function generate_template() {
|
|
let out = typst_header;
|
|
|
|
for(const step_key in steps) {
|
|
console.log(step_key);
|
|
|
|
let result = steps[step_key].result;
|
|
|
|
if(steps[step_key].finalize) {
|
|
steps[step_key].finalize(result);
|
|
}
|
|
|
|
for(const key in result) {
|
|
console.log("- " + key);
|
|
|
|
const search_condition = "<" + step_key + "." + key + ":";
|
|
|
|
while(true) {
|
|
const condition_pos = out.search(search_condition);
|
|
|
|
if(condition_pos < 0) break;
|
|
|
|
const condition_end_pos = out.slice(condition_pos).search(">");
|
|
|
|
if(condition_end_pos >= 0) {
|
|
const head = out.slice(0, condition_pos);
|
|
const meat = 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 + "}";
|
|
|
|
while(true) {
|
|
const replacement_pos = out.search(search_replacement);
|
|
|
|
if(replacement_pos < 0) break;
|
|
|
|
const head = out.slice(0, replacement_pos);
|
|
const meat = result[key];
|
|
const tail = out.slice(replacement_pos + search_replacement.length);
|
|
|
|
out = head + meat + tail;
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(out);
|
|
|
|
return out;
|
|
}
|
|
|
|
async function generate_zip() {
|
|
let assets_zip = await fetch("template.zip");
|
|
let out_zip = await new JSZip().loadAsync(await assets_zip.blob());
|
|
|
|
out_zip.file("thesis.typ", generate_template());
|
|
|
|
if(!steps.assignment.result.include_pdf) {
|
|
out_zip.remove("assignment.pdf");
|
|
}
|
|
|
|
return await out_zip.generateAsync({ type: "blob" });
|
|
}
|
|
|