Skip to content

Commit

Permalink
调整 README.md 更新逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 12, 2023
1 parent ac44ea9 commit 0ad15e7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 98 deletions.
75 changes: 0 additions & 75 deletions assets/templates/README.md

This file was deleted.

40 changes: 40 additions & 0 deletions services/publish_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,43 @@ def deploy_www():
for git_deploy_config in configs.git_deploy_configs:
repo.git.remote('add', git_deploy_config.remote_name, git_deploy_config.url)
repo.git.push(git_deploy_config.remote_name, f'{current_branch_name}:{git_deploy_config.branch_name}', '-f')


def update_readme_md():
file_path = os.path.join(path_define.project_root_dir, 'README.md')

front_lines = []
back_lines = []
with open(file_path, 'r', encoding='utf-8') as file:
current_lines = front_lines
for line in file.readlines():
line = line.rstrip()
if line == '可以通过 [主页](https://retro-pixel-font.takwolf.com) 实时预览字体效果。':
current_lines.append(line)
current_lines.append('')
current_lines = None
elif line == '## 下载':
current_lines = back_lines
current_lines.append(line)
elif current_lines is not None:
current_lines.append(line)

preview_lines = []
for font_config in configs.font_configs:
preview_lines.append(f'### {font_config.name}')
preview_lines.append('')
info = f'尺寸:{font_config.size}px / 行高:{font_config.line_height}px · '
info += f'[实时预览](https://retro-pixel-font.takwolf.com#font-{font_config.outputs_name}) · '
info += f'[字母表](https://retro-pixel-font.takwolf.com/{font_config.outputs_name}/alphabet.html) · '
info += f'[示例文本](https://retro-pixel-font.takwolf.com/{font_config.outputs_name}/demo.html)'
preview_lines.append(info)
preview_lines.append('')
preview_lines.append(f'{font_config.readme_intro}')
preview_lines.append('')
preview_lines.append(f'![preview-{font_config.outputs_name}](docs/{font_config.outputs_name}/preview.png)')
preview_lines.append('')

with open(file_path, 'w', encoding='utf-8') as file:
file.write('\n'.join(front_lines + preview_lines + back_lines))
file.write('\n')
logger.info(f"Make readme markdown file: '{file_path}'")
21 changes: 0 additions & 21 deletions services/template_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,3 @@ def make_itch_io_details_html_file():
with open(file_path, 'w', encoding='utf-8') as file:
file.write(html)
logger.info(f"Make itch.io details html file: '{file_path}'")


def make_readme_md_file():
preview = ''
for font_config in configs.font_configs:
preview += f'### {font_config.name}\n\n'
preview += f'尺寸:{font_config.size}px / 行高:{font_config.line_height}px · '
preview += f'[实时预览](https://retro-pixel-font.takwolf.com#font-{font_config.outputs_name}) · '
preview += f'[字母表](https://retro-pixel-font.takwolf.com/{font_config.outputs_name}/alphabet.html) · '
preview += f'[示例文本](https://retro-pixel-font.takwolf.com/{font_config.outputs_name}/demo.html)\n\n'
preview += f'{font_config.readme_intro}\n\n'
preview += f'![preview-{font_config.outputs_name}](docs/{font_config.outputs_name}/preview.png)\n\n'
preview = preview.strip()

template = _environment.get_template('README.md')
markdown = template.render(preview=preview)
file_path = os.path.join(path_define.project_root_dir, 'README.md')
with open(file_path, 'w', encoding='utf-8') as file:
file.write(markdown)
file.write('\n')
logger.info(f"Make readme markdown file: '{file_path}'")
4 changes: 2 additions & 2 deletions tasks/update_docs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging

from services import template_service, publish_service
from services import publish_service

logging.basicConfig(level=logging.DEBUG)


def main():
template_service.make_readme_md_file()
publish_service.update_readme_md()
publish_service.update_docs()


Expand Down

0 comments on commit 0ad15e7

Please sign in to comment.