[+] Assign ids
This commit is contained in:
@@ -29,7 +29,7 @@ if __name__ == '__main__':
|
||||
file = 'content/posts/' + b
|
||||
with open(file, 'r', encoding='utf-8') as f:
|
||||
yml, md = re.split('---+\n', f.read().strip())[1:]
|
||||
post = {**yaml.safe_load(yml), 'file': file}
|
||||
post = {'id': 0, **yaml.safe_load(yml), 'file': file}
|
||||
posts.append(post)
|
||||
post.setdefault('tags', [])
|
||||
|
||||
@@ -48,6 +48,10 @@ if __name__ == '__main__':
|
||||
|
||||
posts.sort(key=lambda x: x['date'], reverse=True)
|
||||
|
||||
# Give every post an id based on index
|
||||
for i, p in enumerate(posts):
|
||||
p['id'] = i
|
||||
|
||||
# Count tags and categories
|
||||
tags = Counter([t for p in posts for t in p['tags']])
|
||||
cats = Counter([p['category'] for p in posts if 'category' in p])
|
||||
|
||||
Reference in New Issue
Block a user