Skip to content
Merged

Sync #116

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9a3c03a
Merge pull request #87 from Julian-Mostbauer/master
adirnberger-htl Jan 16, 2025
65dff15
Merge pull request #100 from Julian-Mostbauer/master
adirnberger-htl Jan 21, 2025
4f394d1
add use case diagram
adirnberger-htl Jan 21, 2025
91883e1
Rename UseCaseDiagram.png to useCaseDiagram.png
adirnberger-htl Jan 21, 2025
457566f
Merge pull request #105 from Julian-Mostbauer/master
adirnberger-htl Jan 21, 2025
df0d866
added search functionality
Julian-Mostbauer Jan 21, 2025
d0f6b53
major component update.
Julian-Mostbauer Jan 21, 2025
a64306a
improved onMount to access comp props
Julian-Mostbauer Jan 21, 2025
97cd39a
working onMount system
Julian-Mostbauer Jan 21, 2025
c0d062a
synchro fix comp builder
Julian-Mostbauer Jan 21, 2025
46269ee
safety commit for backup
Julian-Mostbauer Jan 21, 2025
1dccf56
converted imgs to webp
Julian-Mostbauer Jan 21, 2025
05c33eb
- optimizied components
Julian-Mostbauer Jan 21, 2025
a12637c
- added persistant cache to file content.
Julian-Mostbauer Jan 21, 2025
d6a169a
Merge pull request #111 from Julian-Mostbauer/master
adirnberger-htl Jan 22, 2025
1a2fb3f
finding logos for all pages in #104
adirnberger-htl Jan 22, 2025
10982b6
Merge pull request #112 from Julian-Mostbauer/dev-arthur
Julian-Mostbauer Jan 22, 2025
2fa77ab
further optimizations
Julian-Mostbauer Jan 22, 2025
7d77e3d
Merge branch 'master' of https://github.com/Julian-Mostbauer/LinuxRic…
Julian-Mostbauer Jan 22, 2025
62bbf77
changed fake transparent images
Julian-Mostbauer Jan 22, 2025
b2f2861
- new syntax for components
Julian-Mostbauer Jan 22, 2025
5c536e1
working navbar search
Julian-Mostbauer Jan 22, 2025
577b8e9
changed index to load components async
Julian-Mostbauer Jan 23, 2025
02ab319
updated to use new component syntax
Julian-Mostbauer Jan 23, 2025
6a31387
changed and unifed head of all pages
Julian-Mostbauer Jan 23, 2025
5abd3ff
Merge pull request #113 from Julian-Mostbauer/master
adirnberger-htl Jan 23, 2025
23bcc54
starting to impliment the skeleton for every distro's history page
adirnberger-htl Jan 23, 2025
1d6ac83
impliment the skeleton for every distro's history page PT.2
adirnberger-htl Jan 23, 2025
4fc4336
impliment the skeleton for every distro's history page PT.3
adirnberger-htl Jan 23, 2025
0fcfac6
Merge pull request #114 from Julian-Mostbauer/dev-arthur
Julian-Mostbauer Jan 23, 2025
8dd1d75
fixed history imports of css and js
Julian-Mostbauer Jan 23, 2025
935d224
applied project required formating
Julian-Mostbauer Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
*.pdf
node_modules
node_modules
*.py
Binary file removed assets/img/card-desktop-environments.jpg
Binary file not shown.
Binary file added assets/img/card-desktop-environments.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/img/card-distributions.jpeg
Binary file not shown.
Binary file added assets/img/card-distributions.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/img/card-package-managers.png
Binary file not shown.
Binary file added assets/img/card-package-managers.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/img/card-setups.jpg
Binary file not shown.
Binary file added assets/img/card-setups.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/img/card-shells.jpg
Binary file not shown.
Binary file added assets/img/card-shells.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/img/card-terminal-themes.jpg
Binary file not shown.
Binary file added assets/img/card-terminal-themes.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/img/card-terminals.jpg
Binary file not shown.
Binary file added assets/img/card-terminals.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/img/card-window-manager.jpg
Binary file not shown.
Binary file added assets/img/card-window-manager.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/card-big-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ const cardCode = `
</div>
`

const cardBuilder = new ComponentBuilder(cardCode, 'card-big-image')
const cardBuilder = new ComponentBuilder('card-big-image', cardCode)
cardBuilder.build()
2 changes: 1 addition & 1 deletion src/components/card-small-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ const cardCode = `
</div>
`

const cardBuilder = new ComponentBuilder(cardCode, 'card-small-image')
const cardBuilder = new ComponentBuilder('card-small-image', cardCode)
cardBuilder.build()
218 changes: 141 additions & 77 deletions src/components/component-builder.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,83 @@
const errorCompStyle = `border: 1px solid red;
padding: 10px; display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
max-width: fit-content;
margin: 0 auto;
margin-top: 1rem;
border-radius: 5px;`

class Component {
componentCode = ''
scriptElement = null
props = {}
errors = []

constructor(componentCode, scriptElement) {
constructor(componentSpawnElement, componentName, componentCode, onMount) {
this.componentCode = componentCode
this.scriptElement = scriptElement
this.componentSpawnElement = componentSpawnElement
this.onMount = onMount
this.componentName = componentName

this.props = {}
this.errors = []
this.buildInProps = []

this.generateBuildInProps()
this.collectProps()
this.insertProps()
this.validateProps()
if (this.errors.length > 0) return

this.totalProps = { ...this.buildInProps, ...this.props }
console.table(this.totalProps)
}

generateBuildInProps() {
this.buildInProps = {
'component-name': this.componentName,
'component-code': this.componentCode,
'component-props': JSON.stringify(this.props),
'component-unique-id': crypto.randomUUID(),
}
}

collectProps() {
const attributes = this.scriptElement.attributes
const attributes = this.componentSpawnElement.attributes
for (let i = 0; i < attributes.length; i++) {
const attr = attributes[i]
if (attr.name.startsWith('data-')) {
if (
attr.name.startsWith('data-') &&
attr.name !== 'data-component' // do not collect the data-component of old syntax
) {
const prop = attr.name.replace('data-', '')
this.props[prop] = attr.value
}
}
}

// Check for missing required props in the component code
const requiredProps = [
...this.componentCode.matchAll(/{{(.*?)}}/g),
].map((match) => match[1])
validateProps() {
const requiredProps = new Set(
[...this.componentCode.matchAll(/{{(.*?)}}/g)].map(
(match) => match[1]
)
)

Object.keys(this.props).forEach((prop) => {
if (!requiredProps.has(prop)) {
this.errors.push(
`Property <mark>${prop}</mark> is not recognized by the component.`
)
delete this.props[prop]
}
})

requiredProps.forEach((prop) => {
if (!(prop in this.props)) {
this.errors.push(
`Property <mark>${prop}</mark> is required but not provided.`
)
this.props[prop] = null
delete this.props[prop]
}
})

// Check for unexpected props in the component code
const unexpectedProps = Object.keys(this.props).filter(
(prop) => !requiredProps.includes(prop)
)

unexpectedProps.forEach((prop) => {
if (prop === 'component') return // Ignore the component name
this.errors.push(
`Property <mark>${prop}</mark> is not recognized by the component.`
)
delete this.props[prop]
})
}

insertProps() {
if (this.errors.length > 0) {
// Build error component
this.componentCode = `
<div style="${errorCompStyle}">
<h2 style="color: red">Component Error</h2>
<h3 style="color: yellow">${this.props.component}</h3>
<div style="color: grey;">
<ul>
${this.errors
.map((error) => `<li>${error}</li>`)
.join('')}
</ul>
</div>
<div>
`
return
// Replace internal props ||name||
for (const [prop, value] of Object.entries(this.buildInProps)) {
const internalPropRegex = new RegExp(`\\|\\|${prop}\\|\\|`, 'g')
this.componentCode = this.componentCode.replace(
internalPropRegex,
value || ''
)
}

// Replace custom props {{name}}
for (const [prop, value] of Object.entries(this.props)) {
const propRegex = new RegExp(`{{${prop}}}`, 'g')
this.componentCode = this.componentCode.replace(
Expand All @@ -88,42 +87,107 @@ class Component {
}
}

placeComponent() {
if (this.errors.length > 0) {
console.error('Invalid component. Cannot place component.')
this.errors.forEach((error) => console.error(error))
}

buildComponent() {
const template = document.createElement('template')
template.innerHTML = this.componentCode.trim()

const content = template.content.cloneNode(true)
this.scriptElement.replaceWith(content)
this.componentSpawnElement.replaceWith(content)
}

generateErrorComponent() {
console.error('Invalid component. Cannot place component.')
this.errors.forEach((error) => console.error(error))

this.componentCode = `
<div style="border: 1px solid red;
padding: 10px; display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
max-width: fit-content;
margin: 0 auto;
border-radius: 5px;">
<h2 style="color: red">Component Error</h2>
<h3 style="color: yellow">${this.componentName}</h3>
<div style="color: grey;">
<ul>
${this.errors.map((error) => `<li>${error}</li>`).join('')}
</ul>
</div>
<div>
`
}

async onMountPerfWrapper() {
try {
var startTime = performance.now()
await this.onMount(this.totalProps)
} catch (e) {
console.error('Error: onMount function failed')
console.error(e)
} finally {
console.info('OnMount ran in', performance.now() - startTime, 'ms')
}
}

async placeComponent() {
if (this.errors.length > 0) {
this.generateErrorComponent()
} else {
this.insertProps()
}

this.buildComponent()

if (this.onMount === undefined || this.errors.length > 0) return
await this.onMountPerfWrapper()
}
}

export default class ComponentBuilder {
constructor(code, name) {
this.name = name
constructor(componentName, code, onMount = undefined) {
this.componentName = componentName
this.code = code
this.onMount = onMount
}

build() {
document
.querySelectorAll(`script[data-component="${this.name}"]`)
.forEach((scriptTag) => {
const startTime = performance.now()
async build() {
const oldSyntax = `script[data-component="${this.componentName}"]`
const newSyntax = `${this.componentName}`

const comp = new Component(this.code, scriptTag)
comp.placeComponent()
const componentTags = [
...document.querySelectorAll(oldSyntax),
...document.querySelectorAll(newSyntax),
]

console.log(
`Component "${comp.props['component']}" rendered in ${
performance.now() - startTime
}ms`
)
console.log(componentTags)

const startTimes = new Map() // To track start times for each component

// Convert NodeList to Array and map to promises for parallel processing
const promises = Array.from(componentTags).map(async (componentTag) => {
const startTime = performance.now()
startTimes.set(componentTag, startTime)

const comp = new Component(
componentTag,
this.componentName,
this.code,
this.onMount
)
await comp.placeComponent()

console.info(
`Component "${comp.componentName}" rendered in ${
performance.now() - startTime
}ms`
)
return comp
})

console.table(comp.props)
})
// Wait for all components to render
await Promise.all(promises)
console.info(`All components of ${this.componentName} rendered.`)
}
}
Loading