Skip to content

Commit

Permalink
Add added field #2353
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed May 4, 2024
1 parent f5071fe commit 983c5ba
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
17 changes: 14 additions & 3 deletions _ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ def parse_global_tags(site, item, tag, item_key: str):


def parse_item(entry, entry_tags=[], meta={}, meta_tags=[]):
updated = entry.get('updated') or date(1970, 1, 1)
updated = entry.get('updated')
if isinstance(updated, str):
updated = datetime.strptime(updated, "%Y-%m-%d").date()
added = entry.get('added') or date.min
if isinstance(added, str):
added = datetime.strptime(added, "%Y-%m-%d").date()
result = dict(entry,
new=(date.today() - updated) < timedelta(days=30),
new=added == updated and (date.today() - added) < timedelta(days=30),
is_updated=(date.today() - updated) < timedelta(days=30),
tags=parse_tags(entry, entry_tags) + parse_tags(meta, meta_tags),
updated=updated)

Expand Down Expand Up @@ -316,6 +320,13 @@ def has_no_status(clone) -> bool:

if isinstance(clone['updated'], str):
clone['updated'] = datetime.strptime(clone['updated'], "%Y-%m-%d").date()
if isinstance(clone.get('added'), str):
clone['added'] = datetime.strptime(clone['added'], "%Y-%m-%d").date()
if clone.get('added', date.min) > clone['updated']:
errors.append({
"name": clone['name'],
"error": "Added date is after updated date"
})
if has_no_status(clone):
errors.append({
"name": clone['name'],
Expand All @@ -342,6 +353,6 @@ def has_no_status(clone) -> bool:
(game.names, game.meta, clone)
for game in site.games
for clone in game.clones
if clone['new']
if clone['is_updated']
], key=lambda args: args[2]['updated'], reverse=True)
}
7 changes: 7 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ const checkHasImagesOrVideos = game => {
}
}

const checkHasAdded = game => {
if (!game.added) {
warn(`📅 ${game.name} has no added date`)
}
}

const commonChecks = game => {
checkRepoGoogleCode(game)
checkRepoGit(game)
Expand All @@ -223,6 +229,7 @@ const commonChecks = game => {
checkFrameworkKnown(game)
checkFrameworkUsesLang(game)
checkHasImagesOrVideos(game)
checkHasAdded(game)
}

// -----------
Expand Down
1 change: 1 addition & 0 deletions games/c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@
info: >-
This is a port of Pangea Software’s racing game Cro-Mag Rally to modern
operating systems.
added: '2024-04-13'
updated: '2024-04-13'
images:
- 'https://img.itch.zone/aW1hZ2UvMTU2NDAwNS85MTU3MTc2LnBuZw==/original/aaCbpm.png'
Expand Down
6 changes: 5 additions & 1 deletion schema/games.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ schema;game:
info:
type: str
desc: Any notable information about the game
added:
type: date
format: "%Y-%m-%d"
desc: Date when this game was first added to OSGC
updated:
required: True
type: date
format: "%Y-%m-%d"
desc: Use today's date
desc: Date when this game entry was last updated in OSGC (use today's date)
images:
type: seq
sequence:
Expand Down
17 changes: 11 additions & 6 deletions static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,19 @@ dt { font-weight: bold; }
dd { padding-left: 1em; padding-bottom: 0.5em; }
dd + dt { margin-top: 1em; }

.new:before {
position: absolute;
content: 'NEW';
margin: 2px 0 0 -55px;
padding: 1px 5px;
font-size: 10px;
.badge-new {
background-color: red;
color: white;
margin-left: 5px;
padding: 2px 5px;
font-size: 12px;
}
.badge-updated {
background-color: red;
color: white;
margin-left: 5px;
padding: 2px 5px;
font-size: 12px;
}

.note { color: grey; }
Expand Down
12 changes: 11 additions & 1 deletion templates/games.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@
{% macro render_clone(names, meta, game, show_details, expand_gallery) %}
<div itemscope="" itemtype="http://schema.org/SoftwareSourceCode">
{%- set show_gallery = show_details and ('images' in game or 'video' in game) -%}
<dd class="searchable {% if game.new %}new{% endif %}"
<dd class="searchable
{% if game.new -%}
new
{%- elif game.is_updated -%}
updated
{%- endif -%}"
data-name="{{ game.name }}"
data-parent="
{%- if names.0 is string -%}
Expand All @@ -84,6 +89,11 @@
{%- else -%}
<span itemprop="name">{{ game['name'] }}</span>
{%- endif %}
{%- if game.new -%}
<span class="badge-new">NEW</span>
{%- elif game.is_updated -%}
<span class="badge-updated">UPDATED</span>
{%- endif -%}
{%- if 'feed' in game %}
<a href="{{ game['feed'] }}" class="feed-icon" title="Feed"><span class="fas fa-rss"></span></a>
{%- endif %}
Expand Down

0 comments on commit 983c5ba

Please sign in to comment.