Skip to content

Commit

Permalink
Merge pull request #454 from Xpirix/task_to_update_news_bar
Browse files Browse the repository at this point in the history
Task to update news bar
  • Loading branch information
timlinux authored Oct 7, 2024
2 parents f63a508 + 151563d commit 98d23cd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
6 changes: 0 additions & 6 deletions content/news/amy.md

This file was deleted.

10 changes: 10 additions & 0 deletions data/feed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"pk": 65,
"publish_from": 1699633377.0,
"publish_to": 1731255779.0,
"title": "OSGeo Statement: EU Cyber Resilience Act",
"image": "https://feed.qgis.org/media/feedimages/2023/11/09/europe.jpg",
"content": "<p>The Cyber Resilience Act will, by design, place considerable strain on the Open Source Geospatial Foundation and the service providers who power so much of our ecosystem. The OSGeo community has been active during this process lending their voice of concern, feedback, and moral objection (not everything is a product!) and support. We encourage you to get informed and lend your voice of support to ensure that these laws do not jeopardise or impact projects like QGIS. <strong>Double-click this entry to learn more.</strong></p>",
"url": "https://www.osgeo.org/foundation-news/eu-cyber-resilience-act/",
"sticky": false
}
27 changes: 26 additions & 1 deletion fetch_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ def fetch_blog_feed(showcase_type, rss_url):
print(f"Writing: {image_filename}")
del response

def fetch_first_feed_entry():
"""
Fetch the first entry from the QGIS feed and save it to data/feed.json
"""
feed_url = "https://feed.qgis.org/?lang=en&json=1"
feed_file_path = "data/feed.json"
response = requests.get(feed_url)
response.raise_for_status()
feed_data = response.json()

if feed_data and len(feed_data) > 0:
first_entry = feed_data[0]
os.makedirs(os.path.dirname(feed_file_path), exist_ok=True)
with open(feed_file_path, "w", encoding="utf-8") as f:
json.dump(first_entry, f, ensure_ascii=False, indent=4)
print(f"First feed entry saved to {feed_file_path}")
else:
print("No items found in the feed.")


parser = argparse.ArgumentParser(description='Import items from various feeds.')
parser.add_argument(
Expand Down Expand Up @@ -232,4 +251,10 @@ def fetch_blog_feed(showcase_type, rss_url):
rss_url="https://raw.githubusercontent.com/qgis/QGIS-Website/main/source/feeds/qugsnews.atom"
)
except Exception as e:
print(f"Error fetching QUG blog feed: {e}")
print(f"Error fetching QUG blog feed: {e}")

try:
# QGIS feed
fetch_first_feed_entry()
except Exception as e:
print(f"Error fetching feed: {e}. Keeping the previous feed.json if it exists.")
22 changes: 6 additions & 16 deletions themes/hugo-bulma-blocks-theme/layouts/partials/contextmenu.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<div class="box mb-0 context-container" id="context">
<div class="container is-flex is-justify-content-space-between">
<div class="rss-feed">
{{ $data := "" }}
{{ $url := .Site.Params.newsfeed }}
{{ with resources.GetRemote $url }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ $data := .Site.Data.feed }}
{{ with $data }}
<a href="{{ .url | safeURL }}" target="_blank" rel="noopener" class="external-link">
{{ .title }}
</a>
{{ else }}
{{ $data = .Content | transform.Unmarshal }}
{{ with $data }}
{{ range . | first 1 }}
<a href="{{ .url | safeURL }}" target="_blank" rel="noopener" class="external-link">
{{ .title }}
</a>
{{ end }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $url }}
{{ errorf "Unable to get data from Site.data.feed" }}
{{ end }}
</div>
<div id="search-control" class="control has-icons-right search-control">
Expand Down

0 comments on commit 98d23cd

Please sign in to comment.