Skip to content

Commit

Permalink
fix(generate): improve id assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Dec 10, 2023
1 parent 0a91161 commit 40ef284
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/runners/generate/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@
post['content'] = re.sub(r'!\[\[\.\/(.*)\|(.*)\]\]', r'<figure><img src="{src}/posts/\1" /><caption>\2</caption></figure>', post['content'])
post['content'] = re.sub(r'!\[\[\.\/(.*)\]\]', r'<img src="{src}/posts/\1" />', post['content'])

# Sort posts by date, such that we have the newst posts first, so that when we loop through them we can give them an id based on their date
posts.sort(key=lambda x: x['date'], reverse=True)

# Give every post an id based on index
# Give every post an id based on the date it was posted
for i, post in enumerate(posts):
post['id'] = len(posts) - i
post['id'] = i + 1

# Count tags
tags = Counter([tag for post in posts for tag in post['tags']])
tags = list(tags.items())

# Pins
pins = [p for p in posts if 'pinned' in p]
pins = [p for p in posts if p['pinned'] != 0]
pins.sort(key=lambda x: x['pinned'])
pins = [p['id'] for p in pins]

Expand Down

0 comments on commit 40ef284

Please sign in to comment.