From 586ce8db703c9e6803c8b58447bacdac05245464 Mon Sep 17 00:00:00 2001 From: Lova Andriarimalala <43842786+Xpirix@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:19:18 +0300 Subject: [PATCH 1/2] Remove unused md file --- content/news/amy.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 content/news/amy.md diff --git a/content/news/amy.md b/content/news/amy.md deleted file mode 100644 index 0a1d8ca10..000000000 --- a/content/news/amy.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -type: "news" -title: "Hello Amy!" -date: 2022-10-19T14:00:00+01:00 -draft: "true" ---- \ No newline at end of file From 151563d7c1eda0ed034913d6d6496bf5ee17cdf4 Mon Sep 17 00:00:00 2001 From: Lova Andriarimalala <43842786+Xpirix@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:19:50 +0300 Subject: [PATCH 2/2] Add a task to update the news bar from the feed website --- data/feed.json | 10 +++++++ fetch_feeds.py | 27 ++++++++++++++++++- .../layouts/partials/contextmenu.html | 22 +++++---------- 3 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 data/feed.json diff --git a/data/feed.json b/data/feed.json new file mode 100644 index 000000000..754cb82f3 --- /dev/null +++ b/data/feed.json @@ -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": "

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. Double-click this entry to learn more.

", + "url": "https://www.osgeo.org/foundation-news/eu-cyber-resilience-act/", + "sticky": false +} \ No newline at end of file diff --git a/fetch_feeds.py b/fetch_feeds.py index 8b81aa2df..d11ff9a6f 100755 --- a/fetch_feeds.py +++ b/fetch_feeds.py @@ -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( @@ -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}") \ No newline at end of file + 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.") \ No newline at end of file diff --git a/themes/hugo-bulma-blocks-theme/layouts/partials/contextmenu.html b/themes/hugo-bulma-blocks-theme/layouts/partials/contextmenu.html index 7b6c4c8e0..a9b06645a 100644 --- a/themes/hugo-bulma-blocks-theme/layouts/partials/contextmenu.html +++ b/themes/hugo-bulma-blocks-theme/layouts/partials/contextmenu.html @@ -1,23 +1,13 @@
- {{ $data := "" }} - {{ $url := .Site.Params.newsfeed }} - {{ with resources.GetRemote $url }} - {{ with .Err }} - {{ errorf "%s" . }} + {{ $data := .Site.Data.feed }} + {{ with $data }} + + {{ .title }} + {{ else }} - {{ $data = .Content | transform.Unmarshal }} - {{ with $data }} - {{ range . | first 1 }} - - {{ .title }} - - {{ end }} - {{ end }} - {{ end }} - {{ else }} - {{ errorf "Unable to get remote resource %q" $url }} + {{ errorf "Unable to get data from Site.data.feed" }} {{ end }}