Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require homepage #76

Closed
wants to merge 10 commits into from
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ The configuration example above changes the default configuration to show all pr
<td>Project will be hidden if it has a less stars on GitHub.</td>
<td><code>100</code></td>
</tr>
<tr>
<td><code>require_homepage</code></td>
<td>If <code>True</code>, all projects without a detected homepage will be hidden.</td>
<td><code>True</code></td>
</tr>
<tr>
<td><code>require_license</code></td>
<td>If <code>True</code>, all projects without a detected license will be hidden.</td>
Expand Down
10 changes: 9 additions & 1 deletion src/best_of/default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def prepare_configuration(cfg: dict) -> Dict:
if "min_stars" not in config:
config.min_stars = 100

if "require_homepage" not in config:
config.require_homepage = True

if "require_license" not in config:
config.require_license = True

Expand All @@ -42,6 +45,11 @@ def prepare_configuration(cfg: dict) -> Dict:

if "generate_install_hints" not in config:
config.generate_install_hints = True
elif "generate_clone_hints" not in config:
config.generate_clone_hints = config.generate_install_hints

if "generate_clone_hints" not in config:
config.generate_clone_hints = False

if "generate_toc" not in config:
config.generate_toc = True
Expand All @@ -62,7 +70,7 @@ def prepare_configuration(cfg: dict) -> Dict:
config.hide_empty_categories = False

if "max_description_length" not in config:
config.max_description_length = 55
config.max_description_length = 100

if "min_description_length" not in config:
config.min_description_length = MIN_PROJECT_DESC_LENGTH
Expand Down
56 changes: 19 additions & 37 deletions src/best_of/generators/markdown_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from best_of import default_config, integrations, utils
from best_of.generators.base_generator import BaseGenerator
from best_of.integrations import github_integration
from best_of.integrations import github_integration, mkdocs_integration
from best_of.license import get_license

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -83,12 +83,10 @@ def generate_metrics_info(project: Dict, configuration: Dict) -> str:
metrics_md = status_md

if metrics_md:
# add divider if metrics are available
metrics_md = "(" + metrics_md + ")"
# remove unnecessary whitespaces
# remove unneccessary whitespaces
utils.clean_whitespaces(metrics_md)
# Add whitespace
metrics_md = metrics_md + " "
# add divider if metrics are available
metrics_md = " - " + metrics_md

return metrics_md

Expand Down Expand Up @@ -153,8 +151,8 @@ def generate_project_labels(project: Dict, labels: list) -> Tuple[str, int]:
label_md = '<a href="' + label_info.url + '">' + label_md + "</a>"

if label_md:
# Add a single space in front of label:
labels_md += " " + label_md.strip()
# Add a separator between labels:
labels_md += " · " + label_md.strip()
labels_text_length += LABEL_SPACING_LENGTH

return (labels_md, labels_text_length)
Expand Down Expand Up @@ -200,7 +198,7 @@ def generate_license_info(project: Dict, configuration: Dict) -> Tuple[str, int]
license_md += " <code>Unlicensed</code>"
else:
license_md += " <code>❗Unlicensed</code>"
return license_md, license_length
return " ·" + license_md, license_length


def generate_project_body(project: Dict, configuration: Dict, labels: list) -> str:
Expand All @@ -226,6 +224,9 @@ def generate_project_body(project: Dict, configuration: Dict, labels: list) -> s
body_md = "\n\n" + body_md
return body_md

mkdocs_prefix, mkdocs_body = mkdocs_integration.MkDocsIntegration.generate_md_details(project, configuration)
body_md += mkdocs_prefix

if project.github_id:
body_md += github_integration.generate_github_details(project, configuration)

Expand All @@ -234,6 +235,8 @@ def generate_project_body(project: Dict, configuration: Dict, labels: list) -> s
if package_manager_id in project and project[package_manager_id]:
body_md += package_manager.generate_md_details(project, configuration)

body_md += mkdocs_body

if not body_md:
# show message if no information is available
body_md = "- _No project information available._"
Expand All @@ -245,7 +248,6 @@ def generate_project_body(project: Dict, configuration: Dict, labels: list) -> s
def generate_project_md(
project: Dict, configuration: Dict, labels: list, generate_body: bool = True
) -> str:

if project.ignore:
return ""

Expand All @@ -258,7 +260,6 @@ def generate_project_md(

metadata_md = ""
if license_md and labels_md:
# TODO: add " · " in between?
metadata_md = license_md + labels_md
elif license_md:
metadata_md = license_md
Expand All @@ -276,41 +277,25 @@ def generate_project_md(
if project.labels:
label_count = len(project.labels)

if license_len:
# Add spacing to length
license_len += 2

desc_length = int(
round(
max(
configuration.max_description_length,
105
- (len(project.name) * 1.3)
- len(metrics_md)
- license_len
- (label_count * 5),
)
)
)
description = utils.process_description(
project.description,
desc_length,
configuration.max_description_length,
ascii_only=configuration.ascii_description,
)

# target="_blank"
if description:
description = f"<br>{description}"
if project.resource:
if description:
description = f"- {description}"
project_md = '🔗&nbsp;<b><a href="{homepage}">{name}</a></b> {metrics} {description}{metadata}\n'.format(
project_md = '🔗&nbsp;<b><a href="{homepage}">{name}</a></b> {metrics}{metadata}{description}\n'.format(
homepage=project.homepage,
name=project.name,
description=description,
metrics=metrics_md,
metadata=metadata_md,
)
elif generate_body:
project_md = '<details><summary><b><a href="{homepage}">{name}</a></b> {metrics}- {description}{metadata}</summary>{body}</details>'.format(
project_md = '<details><summary><b><a href="{homepage}">{name}</a></b> {metrics}{metadata}{description}</summary>{body}</details>'.format(
homepage=project.homepage,
name=project.name,
description=description,
Expand All @@ -320,7 +305,7 @@ def generate_project_md(
)
else:
# don't use details format
project_md = '- <b><a href="{homepage}">{name}</a></b> {metrics}- {description}{metadata}'.format(
project_md = '- <b><a href="{homepage}">{name}</a></b> {metrics}{metadata}{description}'.format(
homepage=project.homepage,
name=project.name,
description=description,
Expand Down Expand Up @@ -386,9 +371,7 @@ def generate_category_md(
+ " hidden projects...</summary>\n\n"
)
for project in category.hidden_projects:
project_md = generate_project_md(
project, config, labels, generate_body=False
)
project_md = generate_project_md(project, config, labels)
category_md += project_md + "\n"
category_md += "</details>\n"

Expand Down Expand Up @@ -552,7 +535,6 @@ def generate_md(categories: OrderedDict, config: Dict, labels: list) -> str:
category_count += 1

if category.projects:

for project in category.projects:
if project.group:
for sub_project in project.projects:
Expand Down
4 changes: 2 additions & 2 deletions src/best_of/integrations/github_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ def generate_github_details(project: Dict, configuration: Dict) -> str:
separator = (
""
if not configuration.generate_badges
and not configuration.generate_install_hints
and not configuration.generate_clone_hints
else ":"
)

details_md = "- [GitHub](" + github_url + ")" + metrics_md + separator + "\n"

if configuration.generate_install_hints:
if configuration.generate_clone_hints:
details_md += "\n\t```\n\tgit clone https://github.com/{github_id}\n\t```\n"
return details_md.format(github_id=github_id)
4 changes: 2 additions & 2 deletions src/best_of/integrations/gitlab_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ def generate_md_details(self, project: Dict, configuration: Dict) -> str:
separator = (
""
if not configuration.generate_badges
and not configuration.generate_install_hints
and not configuration.generate_clone_hints
else ":"
)

details_md = f"- [GitLab]({project.gitlab_url}) {metrics_md}{separator}\n"

if configuration.generate_install_hints:
if configuration.generate_clone_hints:
details_md += f"\n\t```\n\tgit clone {project.gitlab_url}\n\t```\n"

return details_md
65 changes: 65 additions & 0 deletions src/best_of/integrations/mkdocs_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from addict import Dict


def _get_as_list(mapping, key):
names = mapping.get(key, ())
if isinstance(names, str):
names = (names,)
return names


class MkDocsIntegration:
@staticmethod
def generate_md_details(project: Dict, configuration: Dict):
if not configuration.generate_install_hints:
return "", ""

themes = _get_as_list(project, "mkdocs_theme")
plugins = _get_as_list(project, "mkdocs_plugin")
extensions = _get_as_list(project, "markdown_extension")

config_keys = []
yml = yml_main = []
yml_extra = []
if themes:
config_keys.append("theme")
yml += [f"theme: {x}" for x in themes]
yml = yml_extra
if plugins:
config_keys.append("plugins")
theme_prefix = f"{themes[0]}/" if themes else ""
yml += ["plugins:"] + [
f" - {x.removeprefix(theme_prefix)}" for x in plugins
]
if extensions:
config_keys.append("markdown_extensions")
yml += ["markdown_extensions:"] + [f" - {x}" for x in extensions]

if not config_keys:
return "", ""
url = f"https://www.mkdocs.org/user-guide/configuration/#{config_keys[0]}"

if themes:
prefix = (
f'<a href="https://pawamoy.github.io/mkdocs-gallery/themes/{themes[0]}/">\n'
f'<img src="https://pawamoy.github.io/mkdocs-gallery/assets/img/{themes[0]}.png" width="400" align="right">\n'
f"</a>\n\n"
)
else:
prefix = ""

lines = [
f"Add to [mkdocs.yml]({url}):",
"```yaml",
*yml_main,
"```",
]
if yml_extra:
lines += [
"Extras:",
"```yaml",
*yml_extra,
"```",
]
body = "- " + "".join(f" {line}\n" for line in lines).lstrip()
return prefix, body
2 changes: 1 addition & 1 deletion src/best_of/projects_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def apply_filters(project_info: Dict, configuration: Dict) -> None:
project_info.show = False
return

if not project_info.homepage:
if not project_info.homepage and configuration.require_homepage:
log.info(f"Could not find a valid homepage for {project_info.name}")
project_info.show = False

Expand Down
Loading