hyprland-website/src/routes/+page.server.js
Visual-Dawg a77cd33926
Add blog feature (#34)
* better semantics, small improvments

* add blog feature

* update readme

* remove unused import

* Update README.md with typo fix , corrected instructions and improved clarity (#33)

* Update README.md with typo fix,corrected instructions and improved clarity

* Adjust bottom margin for better alignment on devices with >768px height

* newsSlice: adjust gradient

* newsSlice: fix masking

* newsSlice: pedantic alignment of the gradient

---------

Co-authored-by: Ashirbad Sahu <130544212+ashirbadsahu@users.noreply.github.com>
2023-12-17 22:35:11 +00:00

74 lines
1.9 KiB
JavaScript
Executable file

// since there's no dynamic data here, we can prerender
// it so that it gets served as a static asset in production
import baseColors from 'tailwindcss/colors'
export const load = async ({ fetch }) => ({
backgroundData: getHeroBackgroundTiles(),
news: await fetch('/api/news')
.then((response) => response.json())
.then((news) => news.slice(0, 3))
})
function getHeroBackgroundTiles() {
const workspacesPerRow = 4
const workspaceHeight = 240
const gapLength = 32
const colors = [baseColors.blue[500], baseColors.cyan[400], baseColors.sky[500]]
const images = [
'/imgs/chan/joy.svg',
'/imgs/chan/surprise.svg',
'/imgs/chan/tongueout.svg',
'/imgs/waylnad.webp'
]
const leftColumns = Array.from({ length: 3 }, () => generateRow(workspacesPerRow))
const rightColumns = Array.from({ length: 3 }, () => generateRow(workspacesPerRow))
/** Used to transform the rows by their own lenght*/
const height = workspacesPerRow * (workspaceHeight + gapLength)
return {
leftColumns,
rightColumns,
height,
workspacesPerRow,
workspaceHeight,
gapLength
}
function generateRow(amount) {
return Array.from({ length: amount }).map(generateWorkspace)
// If the background should be animated
// return [...base, ...base]
}
function generateWorkspace() {
return [
generateTiles(),
Math.random() > 0.4 ? generateTiles() : undefined,
Math.random() > 0.7 ? generateTiles() : undefined
].filter(Boolean)
}
function generateTiles() {
const result = Math.random() > 0.5 ? [generateTile()] : [generateTile(), generateTile()]
return result
}
function generateTile() {
return { color: getRandomColor(), image: Math.random() > 0.7 ? getRandomImage() : undefined }
}
/** @returns {string} */
function getRandomColor() {
return colors.at(Math.floor(Math.random() * colors.length))
}
/** @returns {string} */
function getRandomImage() {
return images.at(Math.floor(Math.random() * images.length))
}
}