PageSourceSearch

https://reverseagi.ai/assets/js/news.js?v=2

js reverseagi.ai collected 2026-10-05 13:57:44 UTC 3,331 bytes, 111 lines download raw bytes

1import {
2    Pagination
3} from './pager.js';
4
5// 各CSVの配置場所
6const ROOT_PATH = "/contents/csv";
7
8// パラメータ名:カテゴリーID
9const CATEGORY_ID = "category";
10// パラメータ名:NewsID
11const NEWS_ID = "news";
12
13// 1ページに表示するアイテム数
14const MAX_ITEM_NUM = 10;
15// ページネーションの表示数(リンクボタン数)
16const MAX_PAGER_NUM = 3;
17
18
19class NewsPagination extends Pagination {
20    // カテゴリーID
21    categoryId = 0;
22    // ニュースID
23    newsId = 0;
24
25    constructor(maxItemNum, maxPagerNum) {
26        // 1ページに表示するアイテム数
27        if (maxItemNum == null) {
28            maxItemNum = MAX_ITEM_NUM;
29        }
30        // ページネーションの表示数(リンクボタン数)
31        if (maxPagerNum == null) {
32            maxPagerNum = MAX_PAGER_NUM;
33        }
34        // 先に親クラスのコンストラクタを呼び出す
35        super(maxItemNum, maxPagerNum);
36
37        // クエリーのパラメータを取得
38        let params = new URLSearchParams(document.location.search);
39
40        // カテゴリーID
41        if (params.get(CATEGORY_ID) != null) {
42            this.categoryId = parseInt(params.get(CATEGORY_ID));
43        }
44        // ニュースID
45        if (params.get(NEWS_ID) != null) {
46            this.newsId = parseInt(params.get(NEWS_ID));
47        }
48    }
49}
50
51
52async function loadCategories(lang = 'ja') {
53    const response = await fetch(`${ROOT_PATH}/category.csv`, { cache: "no-store" });
54    const text = await response.text();
55    const data = text.trim().split('\n')
56        .map(line => line.split(',').map(x => x.trim()));
57    const nameColIdx = (lang === 'en') ? 2 : 1;
58    const categoryMap = new Map(data.slice(1).map(r => [r[0], r[nameColIdx] || r[1]]));
59    return categoryMap;
60}
61
62async function loadNews(categoryId, lang = 'ja') {
63    const categoryMap = await loadCategories(lang);
64    const response = await fetch(`${ROOT_PATH}/news.csv`, { cache: "no-store" });
65    const text = await response.text();
66    const data = text.trim().split('\n')
67        .map(line => line.split(',').map(x => x.trim()));
68
69    const headers = data[0];  // headerのみ
70    const dataList = data.slice(1)  // データのみ
71        .map(x => new Map([
72            [headers[0], x[0]],
73            [headers[1], x[1]],
74            [headers[2], x[2]],
75            ['title', (lang === 'en' && x[5]) ? x[5] : x[3]],
76            ['text', (lang === 'en' && x[6]) ? x[6] : x[4]],
77            ["category_name", categoryMap.get(x[2])],
78        ]));
79
80    let articles = dataList.filter(item => {
81        return (categoryId == 0) || (categoryId == item.get("category_id"));
82    });
83
84    articles = articles.sort(function (a, b) {
85        return (a.get("publication_date") > b.get("publication_date")) ? -1 : 1;  //オブジェクトの降順ソート
86    });
87
88    return articles;
89}
90
91async function getNews(newsId, lang = 'ja') {
92    // ニュースCSV読み込み
93    const dataList = await loadNews(0, lang);
94    // ニュース検索
95    const articles = dataList.filter(item => {
96        return (newsId == item.get("news_id"));
97    });
98    if (articles.length > 0) {
99        return articles[0];
100    } else {
101        return null;
102    }
103}
104
105export {
106    getNews,
107    loadCategories,
108    loadNews,
109    NewsPagination
110};
111

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.