portal/source/index.html.php

79 lines
1.1 KiB
PHP
Raw Normal View History

2024-06-01 18:53:24 +02:00
<?php
2024-06-02 11:56:52 +02:00
/**
*/
2024-06-01 18:53:24 +02:00
function string_coin(
string $template,
array $arguments
) : string
{
$result = $template;
foreach ($arguments as $key => $value) {
$result = \str_replace(\sprintf('{{%s}}', $key), $value, $result);
}
return $result;
}
2024-06-02 11:56:52 +02:00
/**
*/
2024-06-01 18:53:24 +02:00
function template_render_by_name(
string $template_name,
array $arguments
) : string
{
return string_coin(
2024-06-02 11:56:52 +02:00
\file_get_contents(
string_coin(
'{{directory}}/templates/{{name}}.html.tpl',
[
'directory' => __DIR__,
'name' => $template_name,
]
)
),
2024-06-01 18:53:24 +02:00
$arguments
);
}
2024-06-02 11:56:52 +02:00
/**
*/
2024-06-01 18:53:24 +02:00
function main(
) : void
{
$data = \json_decode(
2024-06-02 11:56:52 +02:00
\file_get_contents(__DIR__ . '/data.json'),
2024-06-01 18:53:24 +02:00
true
);
print(
template_render_by_name(
'main',
[
'title' => $data['title'],
'entries' => \implode(
"\n",
\array_map(
fn($entry) => template_render_by_name(
'entry',
[
'label' => $entry['label'],
'target' => $entry['target'],
2024-06-02 11:56:52 +02:00
'image' => $entry['image'],
2024-06-01 18:53:24 +02:00
]
),
2024-06-02 11:56:52 +02:00
\array_values(\array_filter(
$data['entries'],
fn($entry) => ($entry['active'] ?? true)
))
2024-06-01 18:53:24 +02:00
)
),
]
)
);
}
main();
?>