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// ï¼ãã¼ã¸ã«è¡¨ç¤ºããã¢ã¤ãã æ° 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 // ï¼ãã¼ã¸ã«è¡¨ç¤ºããã¢ã¤ãã æ° 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.