diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 36d6d04..d02bb5b 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -3,6 +3,8 @@ name: Docker Image CI on: push: branches: [ "main" ] + pull_request: + branches: [ "main" ] jobs: @@ -21,4 +23,9 @@ jobs: - name: Build the Docker image run: | docker build . --file Dockerfile --tag ghcr.io/openplaceguide/opg-pages:latest - docker push ghcr.io/openplaceguide/opg-pages:latest + if [ "$CURRENT_BRANCH" = "main" ]; then + echo "On the 'main' branch. Pushing the Docker image..." + docker push ghcr.io/openplaceguide/opg-pages:latest + else + echo "Not on the 'main' branch. Skipping Docker push." + fi diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 0de2f9c..2d8b197 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -32,9 +32,9 @@ jobs: git clone https://github.com/OpenPlaceGuide/data/ opg-data-ethiopia - name: Build run: npm run build + - name: Download TagInfo + run: curl https://taginfo.openstreetmap.org/download/taginfo-wiki.db.bz2 | bunzip2 > database/taginfo-wiki.db - name: Execute tests (Unit and Feature tests) via PHPUnit env: - DB_CONNECTION: sqlite - DB_DATABASE: database/database.sqlite APP_TECHNICAL_CONTACT: alex@addismap.com?subject=CI-Runner run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index fa5ebae..f85762c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ yarn-error.log /.idea /.vscode cache/ +/database/*.db diff --git a/Dockerfile b/Dockerfile index 983e6d1..9df9ed2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,7 @@ EOF EXPOSE 8000 -RUN apk add --no-cache zip php-8.1 php-8.1-intl php-8.1-gd php-8.1-cgi php-8.1-phar php-8.1-iconv php-8.1-mbstring php-8.1-openssl php-8.1-dom php-8.1-curl php-8.1-simplexml +RUN apk add --no-cache zip php-8.1 php-8.1-intl php-8.1-gd php-8.1-cgi php-8.1-phar php-8.1-iconv php-8.1-mbstring php-8.1-openssl php-8.1-dom php-8.1-curl php-8.1-simplexml curl #ENV LOG_CHANNEL=stderr @@ -70,6 +70,7 @@ COPY . /var/www/html RUN mkdir -p storage/framework/cache/data storage/framework/sessions storage/framework/views RUN chown -R www-data:www-data /var/www/html/storage || true RUN chown -R www-data:www-data /var/www/html/bootstrap/cache || true +RUN curl https://taginfo.openstreetmap.org/download/taginfo-wiki.db.bz2 | bunzip2 > database/taginfo-wiki.db COPY --from=composer /var/www/html/vendor /var/www/html/vendor COPY --from=composer /usr/bin/composer /usr/bin/composer diff --git a/README.md b/README.md index ee71635..33b9341 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ cd ../osmapp && docker build --build-arg PROXY_BACKEND=http://opg-pages/ . -t os * build this app ```bash -docker build . -t opg-pages +docker build . --progress=plain -t opg-pages ``` Start diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index b1c262c..2816be0 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -45,4 +45,14 @@ public function register(): void // }); } + + function render($request, Throwable $exception) + { + if ($this->isHttpException($exception)) { + if ($exception->getStatusCode() == 404) { + return response()->view('errors.404', [], 404); + } + } + return parent::render($request, $exception); + } } diff --git a/app/Models/OsmInfo.php b/app/Models/OsmInfo.php index a87965d..100ee80 100644 --- a/app/Models/OsmInfo.php +++ b/app/Models/OsmInfo.php @@ -6,7 +6,7 @@ class OsmInfo { - public function __construct(public readonly OsmId $idInfo, public readonly float $lat, public readonly float $lon, public readonly stdClass $tags, public readonly ?Area $area) + public function __construct(public readonly OsmId $idInfo, public readonly float $lat, public readonly float $lon, public readonly stdClass $tags, public readonly ?Area $area = null) { } diff --git a/app/Services/Repository.php b/app/Services/Repository.php index e95696c..5dc54ce 100644 --- a/app/Services/Repository.php +++ b/app/Services/Repository.php @@ -23,6 +23,9 @@ public static function getInstance(): Repository public function getPlaceInfo($slug): Place { + if (!file_exists($this->getPlaceFileName($slug))) { + abort(404); + } $yamlSource = file_get_contents($this->getPlaceFileName($slug)); $parsed = Yaml::parse($yamlSource); diff --git a/app/Services/TagRenderer.php b/app/Services/TagRenderer.php new file mode 100644 index 0000000..4c49dc1 --- /dev/null +++ b/app/Services/TagRenderer.php @@ -0,0 +1,60 @@ +osmInfo->tags; + $lines = []; + foreach ($tags as $key=>$value) { + if ($key === 'opening_hours') { + $key = 'Opening Times'; + $lines[] = $key . ": " . $value; + continue; + } + + $tagInfo = $this->queryTagInfo($key, $value); + if ($tagInfo !== null) { + $lines[] = $tagInfo; + } + } + + return $lines; + } + + private function queryTagInfo($key, $value) + { + $row = DB::connection('sqlite_taginfo') + ->table('wikipages') + ->select('description') + ->where('lang', 'en') + ->where('key', $key) + ->where('value', $value) + ->get()->first(); + + if ($row === null) { + return null; + } + + return $row->description; + } +} diff --git a/composer.json b/composer.json index f682df2..0d2b19a 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,8 @@ "license": "MIT", "require": { "php": "^8.1", + "ext-dom": "*", + "ext-simplexml": "*", "andreiio/blade-remix-icon": "^2.2", "bame/staticmap": "dev-master", "blade-ui-kit/blade-icons": "^1.5", @@ -13,9 +15,7 @@ "laravel/framework": "^10.0", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.8", - "symfony/yaml": "^6.2", - "ext-simplexml": "*", - "ext-dom": "*" + "symfony/yaml": "^6.2" }, "require-dev": { "fakerphp/faker": "^1.9.1", diff --git a/composer.lock b/composer.lock index 574e9d7..f8748a1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "064c60766c3f8e4ebb15e5ca201542c4", + "content-hash": "3b0e3650e543ec7f94fe93db1fc20fc0", "packages": [ { "name": "andreiio/blade-remix-icon", @@ -8355,8 +8355,8 @@ "prefer-lowest": false, "platform": { "php": "^8.1", - "ext-simplexml": "*", - "ext-dom": "*" + "ext-dom": "*", + "ext-simplexml": "*" }, "platform-dev": [], "platform-overrides": { diff --git a/config/database.php b/config/database.php index 137ad18..af1824d 100644 --- a/config/database.php +++ b/config/database.php @@ -34,13 +34,12 @@ */ 'connections' => [ - - 'sqlite' => [ + 'sqlite_taginfo' => [ 'driver' => 'sqlite', - 'url' => env('DATABASE_URL'), - 'database' => env('DB_DATABASE', database_path('database.sqlite')), + 'url' => '', + 'database' => database_path('taginfo-wiki.db'), 'prefix' => '', - 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), + 'foreign_key_constraints' => true, ], 'mysql' => [ diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php new file mode 100644 index 0000000..52d716e --- /dev/null +++ b/resources/views/errors/404.blade.php @@ -0,0 +1,18 @@ +@extends('layouts.index') + +@section('pageTitle') + Page not found on {{ config('app.name') }} +@endsection + +@section('content') +
+

+ Sorry - Page not found +

+
+
+
+ go to the homepage now +
+
+@stop diff --git a/resources/views/layouts/index.blade.php b/resources/views/layouts/index.blade.php index 31fffc1..3da9cf6 100644 --- a/resources/views/layouts/index.blade.php +++ b/resources/views/layouts/index.blade.php @@ -8,7 +8,7 @@ @vite('resources/js/app.js') + class="relative text-gray-700 bg-gradient-to-br from-white to-{{ $color ?? 'black' }}-100 border-t-2 border-{{ $color ?? 'black' }}-900 min-h-screen">
@yield('content')
diff --git a/resources/views/page/place.blade.php b/resources/views/page/place.blade.php index 3e496f8..3d55100 100644 --- a/resources/views/page/place.blade.php +++ b/resources/views/page/place.blade.php @@ -28,7 +28,7 @@ @if($logoUrl) @else -{{-- @svg("icon-${icon}_11","h-20 w-20 mr-5 mb-4 inline aspect-square fill-current text-$color-900" )--}} + {{-- @svg("icon-${icon}_11","h-20 w-20 mr-5 mb-4 inline aspect-square fill-current text-$color-900" )--}} @endif
@@ -43,7 +43,9 @@ Create URL / Add content @endif

- Welcome to the {{ config('app.name') }} page of {{ Fallback::field($main->tags, 'name') }}, a {{ Fallback::resolve($type->name) }}. + Welcome to the {{ config('app.name') }} page of + {{ Fallback::field($main->tags, 'name') }}, a + {{ Fallback::resolve($type->name) }}.

Media

@@ -67,12 +69,21 @@

{{ Fallback::field($branch->tags, 'name') }}

{{ ucfirst(Fallback::resolve($type->name)) }} @if($branch->area !== null) - in {{ $branch->area->getFullName() }} + in {{ $branch->area->getFullName() }} @endif + + + @php($mainUrl = $branch->idInfo->getOsmUrl(url('/'))) - + Map showing the address of {{  Fallback::field($branch->tags, 'name') }} in three different zoom levels.