Allow to specify homepage banner via ENV. Otherwise the content of the file config/banner.md is used.

This commit is contained in:
Jan Böhmer 2019-10-19 23:20:19 +02:00
parent 5042d5720a
commit 896299bc4d
4 changed files with 36 additions and 2 deletions

4
.env
View file

@ -43,4 +43,8 @@ FIXER_API_KEY=CHANGEME
# In that case all URL contains the index.php front controller in URL # In that case all URL contains the index.php front controller in URL
NO_URL_REWRITE_AVAILABLE=false NO_URL_REWRITE_AVAILABLE=false
# Override value if you want to show to show a given text on homepage.
# When this is empty the content of config/banner.md is used as banner
BANNER=""
### End custom vars ### End custom vars

3
config/banner.md Normal file
View file

@ -0,0 +1,3 @@
Welcome to Part-DB.
<small>If you want to change this banner, edit `config/banner.md` file or set the `BANNER` environment variable.</small>

View file

@ -8,7 +8,7 @@ parameters:
locale: 'en' # Set the default language to use her locale: 'en' # Set the default language to use her
timezone: 'Europe/Berlin' timezone: 'Europe/Berlin'
partdb_title: 'Part-DB' # The title shown inside of Part-DB (e.g. in the navbar and on homepage) partdb_title: 'Part-DB' # The title shown inside of Part-DB (e.g. in the navbar and on homepage)
banner: '' # The info text shown in the homepage banner: '%env(trim:string:BANNER)%' # The info text shown in the homepage, if empty config/banner.md is used
use_gravatar: true # Set to false, if no Gravatar images should be used for user profiles. use_gravatar: true # Set to false, if no Gravatar images should be used for user profiles.
default_currency: 'EUR' # The currency that should be used default_currency: 'EUR' # The currency that should be used
media_directory: 'public/media/' # The folder where uploaded attachment files are saved media_directory: 'public/media/' # The folder where uploaded attachment files are saved

View file

@ -31,18 +31,45 @@
namespace App\Controller; namespace App\Controller;
use App\Services\GitVersionInfo; use App\Services\GitVersionInfo;
use SebastianBergmann\CodeCoverage\Node\File;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Cache\CacheInterface;
class HomepageController extends AbstractController class HomepageController extends AbstractController
{ {
protected $cache;
protected $kernel;
public function __construct(CacheInterface $cache, KernelInterface $kernel)
{
$this->cache = $cache;
$this->kernel = $kernel;
}
public function getBanner() : string
{
$banner = $this->getParameter('banner');
if (empty($banner)) {
$banner_path = $this->kernel->getProjectDir()
. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'banner.md';
return file_get_contents($banner_path);
}
return $banner;
}
/** /**
* @Route("/", name="homepage") * @Route("/", name="homepage")
*/ */
public function homepage(GitVersionInfo $versionInfo) public function homepage(GitVersionInfo $versionInfo)
{ {
return $this->render('homepage.html.twig', [ return $this->render('homepage.html.twig', [
'banner' => $this->getParameter('banner'), 'banner' => $this->getBanner(),
'git_branch' => $versionInfo->getGitBranchName(), 'git_branch' => $versionInfo->getGitBranchName(),
'git_commit' => $versionInfo->getGitCommitHash() 'git_commit' => $versionInfo->getGitCommitHash()
]); ]);