Skip to content

Commit

Permalink
[United Nations] Add UN Photos & UN Site Index commands (#13083)
Browse files Browse the repository at this point in the history
* [United Nations] Add UN Site Index command

* Add UN Photos

* Updates

* Update screenshots

* Add licenes

* Update readme

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: raycastbot <bot@raycast.com>
  • Loading branch information
LitoMore and raycastbot committed Jun 25, 2024
1 parent 8109cd5 commit 008e628
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 35 deletions.
13 changes: 10 additions & 3 deletions extensions/united-nations/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# United Nations Extension

## [Updates] - 2024-06-20

- Fix language settings of Spanish and Portuguese
- Enhance display visuals of Arabic copies
- Add UN Site Index command (Arabic, Chinese, English, French, Russian, Spanish)
- Add UN Photos command

## [Enhancement with Raycast Pro] - 2024-06-18

- Add AI-summarized UN News for Text-to-Speech

## [Initial Version] - 2024-06-09

- View UN Documents
- View UN News
- View UN Press
- Explore UN Documents
- Explore UN News
- Explore UN Press
- Text-to-Speech (requires [Say extension](https://raycast.com/litomore/say))
30 changes: 21 additions & 9 deletions extensions/united-nations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@

Peace, dignity and equality on a healthy planet.

[![united-nations-badge]][united-nations-link]
[![raycast-cross-extension-badge]][raycast-cross-extension-link]
[![raycast-pro-enhanced-badge]][raycast-pro-enhanced-link]

## Features

- View UN Documents
- View UN News
- View UN Press
- Explore UN Documents
- Explore UN News
- Explore UN Photos
- Explore UN Press
- Explore UN Site Index
- Text-to-Speech (requires [Say extension](https://raycast.com/litomore/say))

## Pro Enhanced Features

- AI-summarized UN News for Text-to-Speech

## Configurations
## Languages Support

The UN News command suppport Arabic, Chinese, English, French, Russian, Spanish, Portuguese, Swahili, Hindi and Urdu languages.
| Command | Lanuages |
| -------------- | ------------------------------------------------------------------------------------ |
| UN Documents | English |
| UN Photos | English |
| UN Press | English |
| UN News | Arabic, Chinese, English, French, Russian, Spanish, Portuguese, Swahili, Hindi, Urdu |
| UN Site Index | Arabic, Chinese, English, French, Russian, Spanish |
| Text-to-Speech | Arabic, Chinese, English, French, Russian, Spanish, Poruguese, Hindi |

Text-to-Speech feature suppports Arabic, Chinese, English, French, Russian, Spanish, Poruguese, and Hindi languages.
## Configurations

You can switch text-to-speech languages from the [Configure Say](https://raycast.com/litomore/say) command. We recommend using Siri voices for the best experience.

Expand All @@ -33,8 +41,12 @@ See [CONTRIBUTING.md](https://github.com/raycast/extensions/blob/main/extensions

MIT

[united-nations-badge]: https://img.shields.io/badge/United%20Nations-009EDB?logo=unitednations&logoColor=fff&style=flat-square
[united-nations-link]: https://www.un.org
The MIT license grant is not for United Nations' resources, which inculde databases, treaty collection, web links, emblem, maps, multimedias.
United Nations reserves all copyright rights in and to all United Nations trademarks.

- [Terms and conditions of use of United Nations websites](https://www.un.org/en/about-us/terms-of-use)
- [UN Photo Usage Guidelines](https://media.un.org/photo/en/guidelines)

[raycast-cross-extension-badge]: https://shields.io/badge/Raycast-Cross--Extension-eee?labelColor=FF6363&logo=raycast&logoColor=fff&style=flat-square
[raycast-cross-extension-link]: https://github.com/LitoMore/raycast-cross-extension-conventions
[raycast-pro-enhanced-badge]: https://shields.io/badge/Raycast-Pro_Enhanced-eee?labelColor=FF6363&logo=raycast&logoColor=fff&style=flat-square
Expand Down
Binary file modified extensions/united-nations/metadata/united-nations-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extensions/united-nations/metadata/united-nations-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified extensions/united-nations/metadata/united-nations-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 17 additions & 14 deletions extensions/united-nations/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 49 additions & 3 deletions extensions/united-nations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,23 @@
"description": "Global perspective Human stories.",
"mode": "view"
},
{
"name": "un-photos",
"title": "UN Photos",
"description": "United Nations Photo Gallery.",
"mode": "view"
},
{
"name": "un-press",
"title": "UN Press",
"description": "Meetings Coverage and Press Releases",
"mode": "view"
},
{
"name": "un-site-index",
"title": "UN Site Index",
"description": "Site Index of United Nations.",
"mode": "view"
}
],
"preferences": [
Expand Down Expand Up @@ -73,11 +85,11 @@
"title": "Русский"
},
{
"value": "pt",
"value": "es",
"title": "Español"
},
{
"value": "es",
"value": "pt",
"title": "Português"
},
{
Expand All @@ -94,6 +106,40 @@
}
]
},
{
"type": "dropdown",
"title": "Site Index Language",
"name": "siteIndexLanguageCode",
"description": "Display launage for UN Site Index.",
"required": true,
"default": "en",
"data": [
{
"value": "ar",
"title": "العربية"
},
{
"value": "zh",
"title": "中文"
},
{
"value": "en",
"title": "English"
},
{
"value": "fr",
"title": "Français"
},
{
"value": "ru",
"title": "Русский"
},
{
"value": "es",
"title": "Español"
}
]
},
{
"type": "dropdown",
"title": "[Raycast Pro] UN News AI-summerize length",
Expand Down Expand Up @@ -148,7 +194,7 @@
}
],
"dependencies": {
"@raycast/api": "^1.76.0",
"@raycast/api": "^1.77.1",
"@raycast/utils": "^1.15.0",
"cheerio": "^1.0.0-rc.12",
"execa": "^9.2.0",
Expand Down
69 changes: 68 additions & 1 deletion extensions/united-nations/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { XMLParser } from "fast-xml-parser";
import got from "got";
import TurndownService from "turndown";
import { newsFeedUrlDict } from "./constants.js";
import { NewsType, UnDocument, UnPress, UnNews } from "./types.js";
import { NewsType, SiteIndex, UnDocument, UnPhoto, UnPress, UnNews, LanguageCode } from "./types.js";

export const fetchUnDocuments = async () => {
const xml = await got("https://undocs.org/rss/gadocs.xml").text();
Expand Down Expand Up @@ -88,3 +88,70 @@ export const fetchUnNewsDetail = async (link: string) => {
export const fetchUnPressDetail = async (link: string) => {
return fetchDetail(link, ".block-field-block-node-press-body");
};

export const fetchSiteIndex = async (languageCode: LanguageCode) => {
const html = await got(`https://www.un.org/${languageCode}/site-index`).text();
const $ = load(html);
$("style").remove();
$("script").remove();
$(".Site-Index-TopNav").remove();
const siteIndex: SiteIndex = {};

if (languageCode === "ar") {
const selector = ".panel-collapse";
const menu = $(selector + " ul li").get();
let currentCategory = "";
for (const el of menu) {
const element = $(el);
if (element.text().at(0) !== currentCategory) {
currentCategory = element.text().trim().at(0) as string;
siteIndex[currentCategory] = [];
}
const title = element.text().trim();
const link = element.find("a").attr("href") as string;
if (title && link) siteIndex[currentCategory].push({ title, link });
siteIndex[currentCategory].push();
}
return siteIndex;
}

const selector = ".field-type-text-with-summary .field-items";
const menu = $(["h2", "ul li"].map((tag) => `${selector} ${tag}`).join(",")).get();
let currentCategory = "";
for (const el of menu) {
const element = $(el);
// @ts-expect-error: The element has `tagName` property
if (el.tagName === "h2") {
currentCategory = element.text().trim();
siteIndex[currentCategory] = [];
} else {
const title = element.text().trim();
const link = element.find("a").attr("href") as string;
if (title && link) siteIndex[currentCategory].push({ title, link });
}
}
return siteIndex;
};

export const fetchUnPhotos = async (page: number) => {
const html = await got(
`https://media.un.org/photo/en/latest-photos?${new URLSearchParams({ page: String(page) }).toString()}`,
).text();
const $ = load(html);
$("style").remove();
$("script").remove();
const gallery = $(".view-content .media-asset");
const photos: UnPhoto[] = [];
gallery.each((_, el) => {
const card = $(el);
const thumbImage = card.find("img").attr("src") as string;
const sourceImage = card.find(".ajax-popup-link").attr("data-mfp-src") as string;
const pageUrl = card.find(".ajax-popup-link").attr("href") as string;
const title = card.find(".h5").text();
const datetime = card.find("time").text();
if (thumbImage && sourceImage && pageUrl && title && datetime) {
photos.push({ thumbImage, sourceImage, pageUrl: "https://media.un.org" + pageUrl, title, datetime });
}
});
return photos;
};
2 changes: 1 addition & 1 deletion extensions/united-nations/src/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const NewsDetail = ({ news }: { news: UnNews }) => {

const detailMarkdown = [
`## ${news.title}`,
`*${news.source} (${new Date(news.pubDate).toLocaleString()})*`,
`*${news.source} (${new Date(news.pubDate).toLocaleString(newsLanguageCode)})*`,
`> ${news.description}`,
`![](${news.image})`,
...(markdownContent === undefined
Expand Down
12 changes: 12 additions & 0 deletions extensions/united-nations/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export type UnPress = {
creator: string;
};

export type UnPhoto = {
thumbImage: string;
sourceImage: string;
pageUrl: string;
title: string;
datetime: string;
};

export enum LanguageCode {
Arabic = "ar",
Chinese = "zh",
Expand Down Expand Up @@ -77,3 +85,7 @@ export type Internationalization = {
viewByTopic: string;
newsType: Record<NewsAll | NewsRegion | NewsTopic, string>;
};

export type SiteIndexItem = { title: string; link: string };

export type SiteIndex = Record<string, SiteIndexItem[]>;
12 changes: 8 additions & 4 deletions extensions/united-nations/src/un-news.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useEffect, useState } from "react";
import { Action, ActionPanel, Icon, List } from "@raycast/api";
import { Action, ActionPanel, Color, Icon, List, getPreferenceValues } from "@raycast/api";
import { fetchUnNews } from "./api.js";
import { NewsDetail, StopTextToSpeech } from "./components.js";
import { i18n } from "./i18n.js";
import { UnNews, NewsRegion, NewsTopic, NewsType } from "./types.js";

export default function () {
const { newsLanguageCode } = getPreferenceValues<Preferences>();
const [isLoading, setIsLoading] = useState(true);
const [newsList, setNewsList] = useState<UnNews[]>([]);
const [newsType, setNewsType] = useState<NewsType>("all");
Expand Down Expand Up @@ -46,12 +47,15 @@ export default function () {
}
>
{newsList.map((news, index) => {
const date = new Date(news.pubDate).toLocaleDateString();
const date = new Date(news.pubDate).toLocaleDateString(newsLanguageCode);
return (
<List.Item
key={`news-${index}`}
title={news.title}
accessories={[{ text: date }]}
title={newsLanguageCode === "ar" ? "" : news.title}
subtitle={newsLanguageCode === "ar" ? date : undefined}
accessories={
newsLanguageCode === "ar" ? [{ text: { value: news.title, color: Color.PrimaryText } }] : [{ text: date }]
}
actions={
<ActionPanel>
<Action.Push icon={Icon.Snippets} title="View Summary" target={<NewsDetail news={news} />} />
Expand Down
Loading

0 comments on commit 008e628

Please sign in to comment.