Skip to content

Commit

Permalink
WIP build a sub-page for each tag
Browse files Browse the repository at this point in the history
- the full HTML output can be built with sphinx-build -b html -c tests/ tests/awesome-selfhosted-html/ tests/awesome-selfhosted-html/html
- needs pip3 install sphinx sphinx-rtd-theme myst-parser
- TODO fix build warnings
- TODO fix TOC/left sidebar generation (WARNING: Le document n'est inclus dans aucune table des matières de l'arborescence.)
- ref. https://github.com/readthedocs/sphinx_rtd_theme/blob/master/docs/index.rst
- ref. https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html
- ref. https://www.sphinx-doc.org/en/master/usage/quickstart.html
- ref. https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-toctree
- ref. https://myst-parser.readthedocs.io/en/latest/syntax/organising_content.html
- ref. https://github.com/executablebooks/MyST-Parser
  • Loading branch information
nodiscc committed Apr 7, 2023
1 parent 7ca725f commit b144088
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 13 deletions.
45 changes: 32 additions & 13 deletions hecat/exporters/html_singlepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
The authors_file, if set, will be generated from the `git shortlog` of your source directory.
"""

import os
import logging
import ruamel.yaml
from ..utils import load_yaml_data
from ..utils import load_yaml_data, to_kebab_case
from jinja2 import Template

yaml = ruamel.yaml.YAML(typ='safe')
yaml.indent(sequence=4, offset=2)

MARKDOWN_HEAD="""
MARKDOWN_CSS="""
<style>
.tag {
background-color: #DBEAFE;
Expand All @@ -56,7 +57,7 @@
background-color: #FFFCAB;
border-radius: 5px;
padding: 2px 8px 2px 8px;
color: #BB973A;
color: #856000;
font-weight: bold;
display: inline-block;
}
Expand All @@ -70,10 +71,7 @@
}
</style>
"""
MARKDOWN_FOOT = ""
CSS = ""
SOFTWARE_JINJA_MARKDOWN="""
----
## {{ software['name'] }}
Expand All @@ -86,6 +84,7 @@
<span class="external-link"><a href="{% if software['source_code_url'] is defined %}{{ software['source_code_url'] }}{% else %}{{ software['website_url'] }}{% endif %}">Source Code</a></span>
<span class="stars">★{% if software['stargazers_count'] is defined %}{{ software['stargazers_count'] }}{% else %}?{% endif %}</span>
----
"""

def render_markdown_software(software):
Expand All @@ -94,6 +93,21 @@ def render_markdown_software(software):
markdown_software = tm.render(software=software)
return markdown_software

def render_tag_page(step, tag, software_list):
"""render a page containing all items matching a specific tag"""
logging.debug('rendering tag %s', tag['name'])
markdown_software_list = ''
for software in software_list:
if any(license in software['licenses'] for license in step['module_options']['exclude_licenses']):
logging.debug("%s has a license listed in exclude_licenses, skipping", software['name'])
elif any(item == tag['name'] for item in software['tags']):
markdown_software_list = markdown_software_list + render_markdown_software(software)
markdown = '{}{}'.format(MARKDOWN_CSS, markdown_software_list)
output_file_name = step['module_options']['output_directory'] + '/tags/' + to_kebab_case(tag['name'] + '.md')
with open(output_file_name, 'w+', encoding="utf-8") as outfile:
logging.info('writing output file %s', output_file_name)
outfile.write(markdown)

def render_html_singlepage(step):
"""
Render a single-page markdown list of all software, in alphabetical order
Expand All @@ -110,12 +124,17 @@ def render_html_singlepage(step):
if 'output_file' not in step['module_options']:
step['module_options']['output_file'] = 'index.md'
for software in software_list:
markdown_software = render_markdown_software(software)
markdown_software_list = markdown_software_list + markdown_software
markdown = '{}{}{}'.format(MARKDOWN_HEAD, markdown_software_list, MARKDOWN_FOOT)
with open(step['module_options']['output_directory'] + '/' + step['module_options']['output_file'], 'w+', encoding="utf-8") as outfile:
logging.info('writing output file %s', step['module_options']['output_directory'] + '/' + step['module_options']['output_file'])
markdown_software_list = markdown_software_list + render_markdown_software(software)
markdown = '{}{}{}{}'.format(MARKDOWN_CSS, markdown_header, markdown_software_list, markdown_footer)
output_file_name = step['module_options']['output_directory'] + '/' + step['module_options']['output_file']
with open(output_file_name, 'w+', encoding="utf-8") as outfile:
logging.info('writing output file %s', output_file_name)
outfile.write(markdown)
# with open(step['module_options']['output_directory'] + '/simplegrid.css', 'w+', encoding="utf-8") as outfile:
# outfile.write(CSS)
####
try:
os.mkdir(step['module_options']['output_directory'] + '/tags/')
except FileExistsError:
pass
for tag in tags:
render_tag_page(step, tag, software_list)
exit(1)
78 changes: 78 additions & 0 deletions tests/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Configuration file for the Sphinx documentation builder.
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------

project = 'awesome-selfhosted'
author = 'awesome-selfhosted community'
version = '1.0'
release = '1.0'
html_show_copyright = True

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['myst_parser', 'sphinx_rtd_theme']

# Only parse .md files
source_suffix = ['.md']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_show_sphinx = True

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
# html_css_files = ['style.css']

html_theme_options = {
'display_version': True,
'prev_next_buttons_location': 'bottom',
'style_external_links': True,
'vcs_pageview_mode': 'edit',
'collapse_navigation': False,
'sticky_navigation': True,
'navigation_depth': 4, # Defines sidebar navigation depth
'titles_only': False
}

# html_context = {
# "display_gitlab": True, # Integrate Gitlab
# "gitlab_host": "gitlab.com",
# "gitlab_user": "nodiscc", # Username
# "gitlab_repo": "toolbox", # Repo name
# "gitlab_version": "master", # Version
# "conf_py_path": "/doc/md/" # Path in the checkout to the docs root
# }

# exclude_patterns = ['README.md']

# Load the recommonmark auto TOC generator
# It will find any section named as defined in 'auto_toc_tree_section',
# find any bullet lists of relative markdown links
# And use it to generate a TOC and populate the sidebar
# from recommonmark.parser import CommonMarkParser
# from recommonmark.transform import AutoStructify
# def setup(app):
# app.add_config_value('recommonmark_config', {
# 'enable_auto_toc_tree': True,
# 'auto_toc_tree_section': 'Index',
# 'auto_toc_maxdepth': 2, # Defines in-place generated TOC depth, not the sidebar depth
# }, True)
# app.add_transform(AutoStructify)

0 comments on commit b144088

Please sign in to comment.