Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Dynamically load Amtsblatt metadata (#76)
Browse files Browse the repository at this point in the history
* ci(release-please): add config for more changelog sections

* fix(Amtsblatt): Screenshot ratio should be sqrt(2):1

* feat(amtsblatt): dynamically create metadata

* refactor: remove log

* chore(deps): add `spawn-sync` stub to prevent build warnings
  • Loading branch information
kdev committed Feb 19, 2024
1 parent 2d1cbad commit 6dd0409
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 37 deletions.
14 changes: 8 additions & 6 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"eslint-config-prettier": "^9.1.0",
"license-report": "^6.5.0",
"prettier": "3.2.5",
"sass": "^1.71.0"
"sass": "^1.71.0",
"spawn-sync": "^2.0.0"
},
"engines": {
"node": ">=18.0.0"
Expand Down
42 changes: 12 additions & 30 deletions src/app/amtsblatt/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,6 @@ import Row from "react-bootstrap/Row";
import AmtsblattCard from "../components/AmtsblattCard";


const AmtsblattList = [
[
{
text: "Amtsblatt 2024-04",
href: "2024-04.pdf",
},
{
text: "Amtsblatt 2024-03",
href: "2024-03.pdf",
},
{
text: "Amtsblatt 2024-02",
href: "2024-02.pdf",
},
],
[
{
text: "Amtsblatt 2024-01",
href: "2024-01.pdf",
},
],
];

async function fetchPreviews() {
const basePath = path.resolve(process.cwd() + "/public/amtsblatt");
async function getPdfImages(filePath) {
Expand All @@ -50,28 +27,33 @@ async function fetchPreviews() {
}

const blattFileName = (await fs.readdir(basePath)).sort().reverse();
const images = [];
const blattData = [];
for (const doc of blattFileName) {
const img = await getPdfImages(path.resolve(basePath + `/${doc}`));
images.push(img);
blattData.push({
text: `Amtsblatt ${doc.slice(0, -4)}`,
href: doc,
image: `data:image/png;base64,${img}`,
});
}
const splitArray = (array, size) => array.map((val, i) => i % size === 0 && array.slice(i, i + size)).filter(e => e);

return images.map((image) => `data:image/png;base64,${image}`);
return splitArray(blattData, 3);
}

export default async function AmtsblattPage() {
const img = await fetchPreviews()
const amtsblattData = await fetchPreviews()
return (
<Container className="px-4 py-5 my-5 lead w-100">
<Header title="Amtsblatt" />
{AmtsblattList.map((linkTriple, row_idx) => (
{amtsblattData.map((dataTriplet, row_idx) => (
<Row className="g-4 py-5" key={row_idx}>
{linkTriple.map(({ text, href }, col_idx) => (
{dataTriplet.map(({ text, href, image }, col_idx) => (
<Col key={text + col_idx} className="col-sm-8 col-lg-4">
<AmtsblattCard
href={href}
text={text}
image={img[col_idx + 3 * row_idx]}
image={image}
/>
</Col>
))}
Expand Down

0 comments on commit 6dd0409

Please sign in to comment.