Skip to content

Commit

Permalink
Keywords based on harvested files
Browse files Browse the repository at this point in the history
  • Loading branch information
zyzzyxdonta committed Dec 18, 2024
1 parent 9a7a160 commit bf25e2e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/add-plugin-to-marketplace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ body:
multiple: true
options: ["harvest", "process", "curate", "deposit", "postprocess"]

- id: "harvested-files"
type: "input"
attributes:
label: "Harvested files"
description: "The types of files your plugin harvests (if it is a harvest plugin)"
placeholder: "foobar, foobar.yml, foobar.json"

- id: "repository-url"
type: "input"
attributes:
Expand Down
19 changes: 19 additions & 0 deletions docs/source/_ext/plugin_markup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-FileContributor: David Pape

import json
import re
from pathlib import Path
from typing import Any, Dict

Expand Down Expand Up @@ -30,6 +31,19 @@ def log_message(text: str, text2: str = None) -> None:
logger.info(message)


def keywordify(text: str) -> str:
"""Make keyword-friendly text.
The result will only contain lowercase a through z and hyphens, e.g.:
* CITATION.cff → citation-cff
* codemeta.json → codemeta-json
* LICENSE → license
"""
text = text.casefold()
return re.sub(r"[^a-z]", "-", text)


def plugin_to_schema_org(plugin: Dict[str, Any]) -> SchemaOrgSoftwarePublication:
"""Convert plugin metadata from the used JSON format to Schema.org.
Expand All @@ -43,6 +57,11 @@ def plugin_to_schema_org(plugin: Dict[str, Any]) -> SchemaOrgSoftwarePublication
"""
keywords = [f"hermes-step-{step}" for step in plugin.get("steps", [])]

if "harvest" in plugin.get("steps", []) and (
harvested_files := plugin.get("harvested_files", [])
):
keywords += [f"hermes-harvest-{keywordify(file)}" for file in harvested_files]

return SchemaOrgSoftwarePublication(
name=plugin.get("name"),
url=plugin.get("repository_url"),
Expand Down
9 changes: 9 additions & 0 deletions docs/source/plugins-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
Expand Down Expand Up @@ -34,6 +35,14 @@
]
}
},
"harvested_files": {
"type": "array",
"description": "Names of files harvested by a harvest plugin",
"items": {
"type": "string",
"uniqueItems": true
}
},
"repository_url": {
"type": "string",
"description": "Link to the repository where users can find and inspect the source code of the plugin",
Expand Down
3 changes: 3 additions & 0 deletions docs/source/plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
"description": "Harvest plugin for CITATION.cff files.",
"author": "Hermes team",
"steps": ["harvest"],
"harvested_files": ["CITATION.cff"],
"builtin": true
},
{
"name": "codemeta.json Harvester",
"description": "Harvest plugin for codemeta.json files.",
"author": "Hermes team",
"steps": ["harvest"],
"harvested_files": ["codemeta.json"],
"builtin": true
},
{
Expand All @@ -25,6 +27,7 @@
"description": "Harvest plugin for .toml files.",
"author": "Hermes team",
"steps": ["harvest"],
"harvested_files": ["pyproject.toml"],
"repository_url": "https://github.com/softwarepub/hermes-plugin-python",
"pypi_url": "https://pypi.org/project/hermes-plugin-python/"
},
Expand Down

0 comments on commit bf25e2e

Please sign in to comment.