-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add ld+json
metadata to software detail pages
#385
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
95cdbee
Add ld+json metadata to software detail pages
ocaisa bcd3e38
Add newlines
ocaisa c57f3aa
Update inject_ld_json.py
ocaisa 0cd82c8
Add additonal requirements
ocaisa 75b59c5
Update all requirements.txt
ocaisa 37cbeea
Make tests aware of new jsonld data
ocaisa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
site/ | ||
venv* | ||
|
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 @@ | ||
from .inject_ld_json import InjectLDJsonPlugin |
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,28 @@ | ||
import json | ||
from mkdocs.plugins import BasePlugin | ||
from bs4 import BeautifulSoup | ||
|
||
class InjectLDJsonPlugin(BasePlugin): | ||
def on_post_page(self, output, page, config): | ||
"""Inject JSON-LD metadata into the <head> section of the rendered page.""" | ||
|
||
# Get JSON-LD data from page metadata | ||
json_ld = page.meta.get("json_ld") | ||
if not json_ld: | ||
return output # No JSON-LD to inject, return page as is | ||
|
||
# Convert dictionary to JSON string | ||
json_ld_str = json.dumps(json_ld, indent=2) | ||
|
||
# Parse the HTML output | ||
soup = BeautifulSoup(output, "html.parser") | ||
|
||
# Create <script> tag for JSON-LD | ||
script_tag = soup.new_tag("script", type="application/ld+json") | ||
script_tag.string = json_ld_str | ||
|
||
# Find the <head> and insert the script | ||
if soup.head: | ||
soup.head.append(script_tag) | ||
|
||
return str(soup) |
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,2 @@ | ||
mkdocs | ||
beautifulsoup4 |
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,20 @@ | ||
from setuptools import setup, find_packages | ||
|
||
# Read requirements from requirements.txt | ||
def read_requirements(): | ||
with open("requirements.txt", encoding="utf-8") as f: | ||
return f.read().splitlines() | ||
|
||
setup( | ||
name="inject_ld_json", | ||
version="0.1.0", | ||
py_modules=["inject_ld_json"], | ||
packages=find_packages(), | ||
install_requires=read_requirements(), # Use requirements.txt | ||
include_package_data=True, | ||
entry_points={ | ||
"mkdocs.plugins": [ | ||
"inject_ld_json = inject_ld_json:InjectLDJsonPlugin", | ||
] | ||
}, | ||
) |
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
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mdutils | ||
numpy | ||
natsort | ||
natsort | ||
pyyaml |
27 changes: 26 additions & 1 deletion
27
scripts/available_software/tests/data/test_md_template_detailed_science_sol.md
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ocaisa Maybe it makes sense to throw this in a dedicated repo, and publish it on PyPI, so others can also use this plugin, but good enough to park it in our
EESSI/docs
repo for now