-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding simple script for generating changelogs. wip
- Loading branch information
Showing
2 changed files
with
52 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from bs4 import BeautifulSoup | ||
from bs4.element import TemplateString | ||
|
||
# Open the changelog file, split it on <script> tag, use the 0th element | ||
|
||
with open('frontend/src/components/modals/changelog.vue') as f: | ||
template = f.read().split('<script>')[0] | ||
|
||
soup = BeautifulSoup(template, features='html.parser') | ||
|
||
lines = [] | ||
dividers = soup.select('div.divider') | ||
|
||
for div in dividers: | ||
# Get the text from the divider | ||
lines.append(f'## {str([c for c in div.children][1]).strip()}') | ||
|
||
# Iterate through the siblings until we reach another divider | ||
sibling = div.find_next_sibling() | ||
if sibling.name == 'div': | ||
continue | ||
elif sibling.name != 'p': | ||
print('found non p, non div tag', sibling.name) | ||
continue | ||
|
||
while sibling is not None and sibling.name != 'div': | ||
is_info = False | ||
# It's definitely a p tag, got some rules to look at | ||
# If it's info text, add asterisks for italics | ||
if 'has-text-info' in sibling.attrs.get('class', set()): | ||
is_info = True | ||
|
||
# Parse the children elements of the p tag | ||
for child in sibling.children: | ||
if isinstance(child, TemplateString): | ||
line = str(child).strip() | ||
if len(line) == 0: | ||
continue | ||
elif is_info: | ||
lines.append(f'- *{line}*') | ||
else: | ||
lines.append(f'- {line}') | ||
elif child.name == 'ul': | ||
for list_item in child.children: | ||
if not isinstance(list_item, TemplateString): | ||
lines.append(f' - {str(list_item.contents[0]).strip()}') | ||
|
||
sibling = sibling.find_next_sibling() | ||
lines.append('\n') | ||
|
||
print('\n'.join(lines)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters