Skip to content

Commit

Permalink
Generate PDF for web and print separately.
Browse files Browse the repository at this point in the history
Fixes #1.
  • Loading branch information
KockaAdmiralac committed Mar 28, 2021
1 parent 13e901c commit d6cc877
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
doc
pdf
doc2pdf
combined.md
combined.pdf
combined-*
node_modules
39 changes: 27 additions & 12 deletions combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const CATEGORIES = {
// Same as above?
concurrency: 'Konkurentnost',
io: 'Ulaz/izlaz',
ioblock: 'Ulaz/izlaz (blokovski uređaji)',
cmd: 'Komandna linija',
ipc: 'Komunikacija između procesa',
filesystem: 'Fajl sistem',
fsintr: 'Fajl sistem (interfejs)',
fsimpl: 'Fajl sistem (implementacija)',
os : 'Uvod u operativne sisteme'
};
const MONTHS = ['', 'januar', 'februar', 'mart', 'april', 'maj', 'jun', 'jul', 'avgust', 'septembar', 'oktobar', 'novembar', 'decembar'];
Expand All @@ -30,6 +31,7 @@ const TYPES = {
k2: 'drugi kolokvijum',
k3: 'treći kolokvijum'
};
const isWeb = !process.argv.includes('--print');

async function processFile(year, month, type, categories) {
const text = await readFile(`md/${year}/${month}/${type}.md`, {
Expand Down Expand Up @@ -68,13 +70,22 @@ async function getYears() {
}
}

function formatUrls(url, solutionUrl) {
const urlRow = (url && isWeb) ?
`- [Postavka](${BASE_URL}${url})\n` :
'';
const solutionUrlRow = (solutionUrl && isWeb) ?
`- [Rešenje](${BASE_URL}${solutionUrl})\n` :
'';
return `${urlRow}${solutionUrlRow}`;
}

async function main() {
const categories = {};
for (const year of await getYears()) {
for (const month of await readdir(`md/${year}`)) {
for (const typeExt of await readdir(`md/${year}/${month}`)) {

await processFile(year, month, typeExt.split('.')[0], categories);
await processFile(year, month, typeExt.split('.')[0], categories);
}
}
}
Expand Down Expand Up @@ -118,14 +129,18 @@ async function main() {
const footer = await readFile('footer.md', {
encoding: 'utf-8'
});
await writeFile('combined.md', `${header}${Object.entries(categoriesConnected).map(
([category, entries]) => `# ${CATEGORIES[category]}\n${entries.map(
({url, content, year, month, type, task, solutionUrl}) =>
`## ${task}. zadatak, ${TYPES[type]}, ${MONTHS[month]} ${year}.\n- [Postavka](${BASE_URL}${url})\n- [Rešenje](${BASE_URL}${solutionUrl})\n\n${content}`
).join('\n\n')}`
).join('\n\n\\pagebreak\n')}${footer}`, {
encoding: 'utf-8'
});
await writeFile(
isWeb ? 'combined-web.md' : 'combined-print.md',
`${header}${Object.entries(categoriesConnected).map(
([category, entries]) => `# ${CATEGORIES[category]}\n${entries.map(
({url, content, year, month, type, task, solutionUrl}) =>
`## ${task}. zadatak, ${TYPES[type]}, ${MONTHS[month]} ${year}.\n${formatUrls(url, solutionUrl)}\n${content}`
).join('\n\n')}`
).join('\n\n\\pagebreak\n')}${footer}`,
{
encoding: 'utf-8'
}
);
}

main();
14 changes: 12 additions & 2 deletions combine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ if [ -z "$1" ]
then
node combine.js
else
node combine.js "--year=$1"
if [ "$1" == "print" ]
then
node combine.js --print
else
node combine.js "--year=$1"
fi
fi
if [ "$1" == "print" ]
then
pandoc combined-print.md -o combined-print.pdf
else
pandoc combined-web.md -o combined-web.pdf
fi
pandoc combined.md -o combined.pdf
26 changes: 4 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "os1-kolokvijumi",
"version": "1.0.0",
"version": "1.0.1",
"author": {
"name": "Luka Simić",
"email": "[email protected]",
Expand Down

0 comments on commit d6cc877

Please sign in to comment.