Skip to content

Commit c54c04a

Browse files
feat: Add navbar to project exports
1 parent 8b679d0 commit c54c04a

2 files changed

Lines changed: 89 additions & 22 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,22 @@ logo: https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Universitaetsbib
729729
730730
icon: https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Logo_TU_Bergakademie_Freiberg.svg/242px-Logo_TU_Bergakademie_Freiberg.svg.png
731731
732+
# Optional sticky navigation bar at the top of the page.
733+
# 'brand' is the text/logo shown on the left, 'background' sets the bar color,
734+
# 'theme' controls text contrast (dark = white text, light = dark text).
735+
# Each entry in 'links' becomes a nav item.
736+
navbar:
737+
brand: My OER Collection
738+
background: "#0B6E75" # optional, defaults to #0B6E75
739+
theme: dark # dark | light, defaults to dark
740+
links:
741+
- label: Home
742+
url: "#"
743+
- label: Section 1
744+
url: "#section-1"
745+
- label: Section 2
746+
url: "#section-2"
747+
732748
footer: >
733749
Simply add a custom footer - that can also contain HTML
734750
<a href="https://liascript.github.io" target="_blank">Made with LiaScript</a>
@@ -864,6 +880,22 @@ This way you can generate a very detailed project configuration and overview.
864880
865881
**Project settings:**
866882
883+
**Navbar (YAML key):** Add a `navbar` block to your project YAML to generate a sticky navigation bar at the top of the page:
884+
885+
```yaml
886+
navbar:
887+
brand: My OER Collection # text shown on the left side
888+
background: "#0B6E75" # optional bar color (default: #0B6E75)
889+
theme: dark # dark (white text) | light (dark text), default: dark
890+
links:
891+
- label: Home
892+
url: "#"
893+
- label: Section 1
894+
url: "#section-1"
895+
```
896+
897+
If `navbar` is absent, no navigation bar is rendered.
898+
867899
`--project-no-meta` Disable the generation of meta information for OpenGraph and Twitter-cards.
868900
869901
`--project-no-rdf` Disable the generation of JSON-LD.

src/export/project.ts

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,63 +68,63 @@ export function help() {
6868
console.log(COLOR.heading('Project settings:'), '\n')
6969

7070
COLOR.info(
71-
'A project is a bundle for multiple LiaScript resource into a single project overview page, based on a provided yaml description.'
71+
'A project is a bundle for multiple LiaScript resource into a single project overview page, based on a provided yaml description.',
7272
)
7373

7474
console.log(
75-
'\nLearn more: https://www.npmjs.com/package/@liascript/exporter#project \n'
75+
'\nLearn more: https://www.npmjs.com/package/@liascript/exporter#project \n',
7676
)
7777
console.log('Example:')
7878
console.log(
79-
'- Input: https://github.com/LiaBooks/liabooks.github.com/blob/main/project.yaml'
79+
'- Input: https://github.com/LiaBooks/liabooks.github.com/blob/main/project.yaml',
8080
)
8181
console.log('- Output: https://liabooks.github.io')
8282
console.log('')
8383

8484
COLOR.command(
8585
null,
8686
'--project-no-meta',
87-
' Disable the generation of meta information for OpenGraph and Twitter-cards.'
87+
' Disable the generation of meta information for OpenGraph and Twitter-cards.',
8888
)
8989
COLOR.command(
9090
null,
9191
'--project-no-rdf',
92-
' Disable the generation of json-ld.'
92+
' Disable the generation of json-ld.',
9393
)
9494
COLOR.command(
9595
null,
9696
'--project-no-categories',
97-
' Disable the filter for categories/tags.'
97+
' Disable the filter for categories/tags.',
9898
)
9999
COLOR.command(
100100
null,
101101
'--project-category-blur',
102-
' Enable this and the categories will be blurred instead of deleted.'
102+
' Enable this and the categories will be blurred instead of deleted.',
103103
)
104104
COLOR.command(
105105
null,
106106
'--project-generate-scrom12',
107-
'SCORM12 and pass additional scrom settings.'
107+
'SCORM12 and pass additional scrom settings.',
108108
)
109109
COLOR.command(
110110
null,
111111
'--project-generate-scrom2004',
112-
'SCORM2004 and pass additional scrom settings.'
112+
'SCORM2004 and pass additional scrom settings.',
113113
)
114114
COLOR.command(
115115
null,
116116
'--project-generate-ims',
117-
' IMS resources with additional config settings.'
117+
' IMS resources with additional config settings.',
118118
)
119119
COLOR.command(
120120
null,
121121
'--project-generate-pdf',
122-
' PDFs are automatically generated and added to every card.'
122+
' PDFs are automatically generated and added to every card.',
123123
)
124124
COLOR.command(
125125
null,
126126
'--project-generate-cache',
127-
' Only generate new files, if they do not exist.'
127+
' Only generate new files, if they do not exist.',
128128
)
129129
}
130130

@@ -175,7 +175,7 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
175175
let { html, json } = await toCard(
176176
argument,
177177
course.collection[j],
178-
true
178+
true,
179179
)
180180

181181
subCards += `<div class='col-sm-6 col-md-4 col-lg-3 ${
@@ -375,6 +375,7 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
375375
</head>
376376
<body>
377377
378+
${generateNavbar(json.navbar)}
378379
<main>
379380
<div class="container-fluid" ${background} >
380381
<section class="py-5 text-center container">
@@ -423,6 +424,40 @@ export async function exporter(argument: ProjectExportArguments, json: any) {
423424
helper.writeFile(output + '.html', helper.prettify(helper.prettify(html)))
424425
}
425426

427+
function generateNavbar(navbar: any): string {
428+
if (!navbar) return ''
429+
430+
const bg = navbar.background || '#0B6E75'
431+
const theme = navbar.theme === 'light' ? 'navbar-light' : 'navbar-dark'
432+
const brand = navbar.brand || ''
433+
const links: any[] = navbar.links || []
434+
435+
let linkItems = ''
436+
for (let i = 0; i < links.length; i++) {
437+
const link = links[i]
438+
const active = i === 0 ? ' active' : ''
439+
linkItems += `
440+
<li class="nav-item">
441+
<a class="nav-link${active}" href="${link.url || '#'}">${link.label || ''}</a>
442+
</li>`
443+
}
444+
445+
return `
446+
<nav class="navbar navbar-expand-lg ${theme} sticky-top" style="background-color: ${bg};">
447+
<div class="container">
448+
<a class="navbar-brand" href="#">${brand}</a>
449+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
450+
<span class="navbar-toggler-icon"></span>
451+
</button>
452+
<div class="collapse navbar-collapse" id="navbarNav">
453+
<ul class="navbar-nav ms-auto">
454+
${linkItems}
455+
</ul>
456+
</div>
457+
</div>
458+
</nav>`
459+
}
460+
426461
function removeContext(obj) {
427462
for (let key in obj) {
428463
if (obj.hasOwnProperty(key)) {
@@ -485,7 +520,7 @@ function hash(url: string) {
485520
function toLinkCard(
486521
argument: any,
487522
course: any,
488-
small: boolean = false
523+
small: boolean = false,
489524
): string {
490525
if (course.arguments) {
491526
argument = course.arguments.reduce((a, b) => {
@@ -510,14 +545,14 @@ function toLinkCard(
510545
tagList,
511546
{},
512547
course.logo,
513-
course.link
548+
course.link,
514549
)
515550
}
516551

517552
async function toCard(
518553
argument: any,
519554
course: any,
520-
small: boolean = false
555+
small: boolean = false,
521556
): Promise<{ html: string; json: any }> {
522557
// if other parameters are defined for a specific course
523558
// then they are treated
@@ -687,7 +722,7 @@ async function toCard(
687722
overwrite(course.comment, course.data.lia.comment),
688723
tagList,
689724
downloads,
690-
overwrite(course.logo, course.data.lia.definition.logo)
725+
overwrite(course.logo, course.data.lia.definition.logo),
691726
),
692727
json: await RDF.parse(argument, course.data),
693728
}
@@ -709,7 +744,7 @@ function card(
709744
apk?: string
710745
},
711746
img_url?: string,
712-
link?: string
747+
link?: string,
713748
): string {
714749
let image = ''
715750
if (img_url) {
@@ -802,10 +837,10 @@ function card(
802837
${image}
803838
<div class="card-body" style="transform: rotate(0);">
804839
<a href="${link ? '' : 'https://liascript.github.io/course/?'}${
805-
link || url
806-
}" target="${
807-
link && !link.startsWith('http') ? '_self' : '_blank'
808-
}" class="link-dark stretched-link">
840+
link || url
841+
}" target="${
842+
link && !link.startsWith('http') ? '_self' : '_blank'
843+
}" class="link-dark stretched-link">
809844
<h${small ? 6 : 5} class="card-title">${title}</h${small ? 6 : 5}>
810845
</a>
811846
<p class="card-text">${comment}</p>

0 commit comments

Comments
 (0)