Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ MYSQL_ROOT_PASSWORD="rootpassword"
MYSQL_USER="omeka_user"
MYSQL_PASSWORD="omeka_password"
MYSQL_DATABASE="omeka"

SOLR_URL="url/to/solr/instance"
FA_BASE_URL="/fa/findingaid/?id="
DIP_STORE_BASE_URL="/dips"
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ FA_TAG="latest"

PROJECT_ROOT="."

SECRETS_DIR="/home/user/workspaces/exploreuk-web-app/secrets"
HOST_BACKUP_DIR="/home/user/workspaces/exploreuk-web-app/backup-dir"
SOLR_URL="url/to/solr/instance"
FA_BASE_URL="/fa/findingaid/?id="
# /dips or /dipstest
DIP_STORE_BASE_URL="/dips"
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ backup/*
!backup/README.md
/app/dist/*
dist/*
/app/themes/omeukaprologue/assets/css/main.min.css
/app/assets/css/main.min.css
node_modules/
.env*
!.env.ci
!.env.dev
nginx/default.conf
nginx/default.prod.conf
docker-entrypoint-initdb.d/
Expand Down
38 changes: 38 additions & 0 deletions app/application/libraries/ExploreUK/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace ExploreUK;

readonly class Config
{
public function __construct(private array $config)
{
}

public static function fromEnv(): self
{
return new self([
'app_env' => self::ensureEnv('APP_ENV'),
'solr_url' => self::ensureEnv('SOLR_URL'),
'fa_base_url' => self::ensureEnv('FA_BASE_URL'),
'dip_store_base_url' => self::ensureEnv('DIP_STORE_BASE_URL'),
]);
}

public function get(string $key): string
{
if (!array_key_exists($key, $this->config)) {
throw new \RuntimeException("Unknown config key: $key");
}
return $this->config[$key];
}

private static function ensureEnv(string $key): string
{
$value = getenv($key);

if ($value === false || $value === "") {
throw new \RuntimeException("Critical config field missing: $key");
}
return $value;
}
}
68 changes: 68 additions & 0 deletions app/application/libraries/ExploreUK/ContentProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace ExploreUK;

class ContentProvider
{
public function __construct(private string $assetsDir)
{
}

public function popularResources(): array
{
return array_map(
fn (array $item): array => [
'image' => $item['image'] ?? '',
'label' => $item['label'] ?? '',
'url' => $item['url'] ?? '#',
],
$this->load('popular_resources.json'),
);
}

public function additionalResources(): array
{
return array_map(
fn (array $item): array => [
'image' => $item['image'] ?? '',
'label' => $item['label'] ?? '',
'url' => $item['url'] ?? '#',
'description' => $item['description'] ?? '',
],
$this->load('additional_resources.json'),
);
}

public function getRandomBackgroundImage(): array
{
$items = $this->load('background_rotation.json');
$item = $items ? $items[array_rand($items)] : [];
return [
'image' => $item['image'] ?? '',
'label' => $item['label'] ?? '',
'url' => $item['url'] ?? '#',
];
}

// helpers
private function load(string $name): array
{
$path = $this->assetsDir . '/data/' . $name;
if (!file_exists($path)) {
error_log("Missing site asset: $path");
return [];
}
try {
$data = json_decode(
file_get_contents($path),
true,
512,
JSON_THROW_ON_ERROR,
);
return $data['data'] ?? [];
} catch (\JsonException $e) {
error_log("Invalid JSON in $path: " . $e->getMessage());
return [];
}
}
}
Loading