Skip to content

Commit

Permalink
Implementing custom pages (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
liarco committed Jan 13, 2022
1 parent 4dc3a39 commit f3ffb2a
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .do/deploy.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ spec:
- key: APP_ENV
scope: RUN_AND_BUILD_TIME
value: prod
- key: COLLECTION_WEBSITE
scope: RUN_TIME
value: https://www.example.com
- key: COLLECTION_MAX_SUPPLY
scope: RUN_TIME
value: "10000"
Expand Down
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

# General collection settings
COLLECTION_WEBSITE=https://www.example.com/
COLLECTION_MAX_SUPPLY=10000
COLLECTION_ASSETS_EXTENSION=png
COLLECTION_HIDDEN_ASSET_EXTENSION=gif
Expand Down
2 changes: 2 additions & 0 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
twig:
default_path: '%kernel.project_dir%/templates'
globals:
collection_website: '%app.collection_website%'

when@test:
twig:
Expand Down
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
app.cache_expiration: '%env(int:CACHE_EXPIRATION)%'
app.collection_website: '%env(COLLECTION_WEBSITE)%'
app.collection_max_supply: '%env(int:COLLECTION_MAX_SUPPLY)%'
app.collection_assets_extension: '%env(COLLECTION_ASSETS_EXTENSION)%'
app.collection_hidden_asset_extension: '%env(COLLECTION_HIDDEN_ASSET_EXTENSION)%'
Expand Down
5 changes: 5 additions & 0 deletions src/Config/RouteName.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

class RouteName
{
/**
* @var string
*/
final public const ROOT = 'root';

/**
* @var string
*/
Expand Down
41 changes: 41 additions & 0 deletions src/Controller/RootController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Safe NFT Metadata Provider package.
*
* (c) Marco Lipparini <developer@liarco.net>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Controller;

use App\Config\RouteName;
use App\Contract\AbstractNftController;
use RuntimeException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @author Marco Lipparini <developer@liarco.net>
*/
#[Route(
'/',
name: RouteName::ROOT,
)]
final class RootController extends AbstractNftController
{
public function __invoke(): Response
{
$websiteUrl = $this->getParameter('app.collection_website');

if (! is_string($websiteUrl)) {
throw new RuntimeException('Invalid collection website.');
}

return $this->redirect($websiteUrl);
}
}
10 changes: 3 additions & 7 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
<meta charset="UTF-8">
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 128 128%22><text y=%221.2em%22 font-size=%2296%22>⚫️</text></svg>">
{# Run `composer require symfony/webpack-encore-bundle` to start using Symfony UX #}
{% block stylesheets %}
{{ encore_entry_link_tags('app') }}
{% endblock %}

{% block javascripts %}
{{ encore_entry_script_tags('app') }}
{% endblock %}
{% block stylesheets %}{% endblock %}

{% block javascripts %}{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
Expand Down
39 changes: 39 additions & 0 deletions templates/bundles/TwigBundle/Exception/error404.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends 'base.html.twig' %}

{% block title %}Not found!{% endblock title %}

{% block stylesheets %}
<style>
body { background-color: #fff; color: #222; font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; margin: 0; }
.container { margin: 30px; max-width: 600px; }
h1 { color: #dc3545; font-size: 24px; }
h2 { font-size: 18px; }
a, a:visited, a:active, a:link, a:hover { color: inherit; font-weight: bold; text-decoration: underline; }
p.small { font-size: .7em; }
</style>
{% endblock stylesheets %}

{% block body %}
<div class="container">
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "404 Not Found".</h2>

<p>
The requested resource cannot be found, please visit our
<a href="{{ collection_website }}">collection website</a>
for more information about the project.
</p>

{#
The credits below help spreading the word about the project and make the
development possible. Please consider leaving them as they are.
If you wish to put some credits in your website too that would be amazing! :)
#}
<p class="small">
This API was built using the
<a href="https://github.com/liarco-network/safe-nft-metadata-provider" target="_blank">safe NFT metadata provider</a>
by <a href="https://www.liarco.net" target="_blank">Liarco.net</a>.
</p>
</div>
{% endblock body %}

0 comments on commit f3ffb2a

Please sign in to comment.