Skip to content

Commit

Permalink
Added tag category link to tags pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Jul 30, 2023
1 parent 21c0455 commit 655772c
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- name: Build site
run: bin/generate site -v --min --ext '' --prev-db "${{ env.yesterdayDb }}" "${{ env.todayDb }}" gh-pages
| tee out
shell: bash # enable pipefail LOL

- name: Push site
run: |
Expand Down
4 changes: 4 additions & 0 deletions assets/css/250.less
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ p.notice::before {
color: #c5e4fb;
}

p.cat {
text-align: center;
}

.filtered() {
color: #c9b734;
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"joomla/di": "^2",
"monolog/monolog": "^1",
"phptype/date": "^1",
"rybakit/msgpack": "^0.9",
"scriptfusion/static-class": "^1",
"symfony/console": "^6",
"symfony/dotenv": "^6",
Expand Down
64 changes: 63 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Generate/TwigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ScriptFUSION\Steam250\SiteGenerator\Generate;

use ScriptFUSION\Steam250\SiteGenerator\Application;
use ScriptFUSION\Steam250\SiteGenerator\SteamApp\Tag;
use ScriptFUSION\Steam250\SiteGenerator\Tag\Tag;
use ScriptFUSION\Type\Date;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
Expand Down
2 changes: 1 addition & 1 deletion src/Page/PreviewsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Doctrine\DBAL\Connection;
use ScriptFUSION\Steam250\SiteGenerator\Database\Queries;
use ScriptFUSION\Steam250\SiteGenerator\SteamApp\PrimaryTagChooser;
use ScriptFUSION\Steam250\SiteGenerator\Tag\PrimaryTagChooser;

class PreviewsPage extends Page
{
Expand Down
25 changes: 24 additions & 1 deletion src/Ranking/Impl/TagRanking.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@

namespace ScriptFUSION\Steam250\SiteGenerator\Ranking\Impl;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use ScriptFUSION\Steam250\SiteGenerator\Ranking\RankingDependencies;
use ScriptFUSION\Steam250\SiteGenerator\SteamApp\Tag;
use ScriptFUSION\Steam250\SiteGenerator\Tag\Tag;
use ScriptFUSION\Steam250\SiteGenerator\Tag\TagDirectoryStatePacker;

class TagRanking extends DefaultRanking
{
private string $tag;

private Connection $database;

public function __construct(RankingDependencies $dependencies, string $tag)
{
$tagId = Tag::convertTagToId($tag);
parent::__construct($dependencies, "tag/$tagId", 150);

$this->tag = $tag;
$this->database = $dependencies->getDatabase();

$this->setTemplate('tag');
$this->setTitle($tag);
Expand Down Expand Up @@ -45,6 +50,24 @@ public function customizeQuery(QueryBuilder $builder): void
;
}

public function export(): array
{
$cat = $this->fetchTagCategory();

return parent::export() + [
'tag_category' => $cat + ['hash' => TagDirectoryStatePacker::packSingleCategory($cat['id'])],
];
}


private function fetchTagCategory(): array
{
return $this->database->fetchAssociative(
'SELECT tag_cat.* FROM tag_cat JOIN tag ON tag.category = tag_cat.short_name AND tag.name = ? LIMIT 1',
[$this->tag]
);
}

public function getTag(): string
{
return $this->tag;
Expand Down
2 changes: 1 addition & 1 deletion src/Ranking/PageContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use ScriptFUSION\Steam250\SiteGenerator\Ranking\Impl\OwnersRanking;
use ScriptFUSION\Steam250\SiteGenerator\Ranking\Impl\ReviewsRanking;
use ScriptFUSION\Steam250\SiteGenerator\Ranking\Impl\TagRanking;
use ScriptFUSION\Steam250\SiteGenerator\SteamApp\Tag;
use ScriptFUSION\Steam250\SiteGenerator\Tag\Tag;

final class PageContainerFactory
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ranking/Ranking.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use ScriptFUSION\Steam250\SiteGenerator\Page\PreviousDatabase;
use ScriptFUSION\Steam250\SiteGenerator\Page\PreviousDatabaseAware;
use ScriptFUSION\Steam250\SiteGenerator\Rank\Ranker;
use ScriptFUSION\Steam250\SiteGenerator\SteamApp\PrimaryTagChooser;
use ScriptFUSION\Steam250\SiteGenerator\Tag\PrimaryTagChooser;

abstract class Ranking extends Page implements PreviousDatabaseAware
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace ScriptFUSION\Steam250\SiteGenerator\SteamApp;
namespace ScriptFUSION\Steam250\SiteGenerator\Tag;

use ScriptFUSION\StaticClass;

Expand Down
2 changes: 1 addition & 1 deletion src/SteamApp/Tag.php → src/Tag/Tag.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace ScriptFUSION\Steam250\SiteGenerator\SteamApp;
namespace ScriptFUSION\Steam250\SiteGenerator\Tag;

use ScriptFUSION\StaticClass;

Expand Down
16 changes: 16 additions & 0 deletions src/Tag/TagDirectoryStatePacker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

namespace ScriptFUSION\Steam250\SiteGenerator\Tag;

use MessagePack\Packer;

final class TagDirectoryStatePacker
{
public static function packSingleCategory(int $categoryId): string
{
$packer = new Packer();

return rtrim(base64_encode($packer->packInt(0) . $packer->packInt(1 << $categoryId)), '=');
}
}
6 changes: 6 additions & 0 deletions template/tag.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
Top {{ games|length }} best Steam games of all time tagged with <em>{{ ranking.tag }}</em>,
according to gamer reviews.
</p>
<p class="cat">
Category
<a href="{{ club250 }}/tags#{{ tag_category.hash }}" class="tag {{ tag_category.short_name }}">
{{ tag_category.name }}
</a>
</p>
{% if ranking.id == 'tag/free_to_play' %}
{{ include('partial/price_button_group.twig') }}
{% endif %}
Expand Down

0 comments on commit 655772c

Please sign in to comment.