aboutsummaryrefslogtreecommitdiff
path: root/src/js/arching-kaos-modules-news.js
blob: 1834d2c199950f7a77cc5139d23ecfd5e39b5700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Arching Kaos Module News
//
// Kaotisk Hund - 2024
//
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
//

import { makeElement } from "./arching-kaos-generator.js";
import { archingKaosFetchText } from "./arching-kaos-fetch.js";
import {
    getNicknameAssossiatedWithGPG,
    getFullText,
    getPreviewText
} from "./arching-kaos-tools.js";
import { getIPFSURL } from "./url-generators.js";

export function akModuleNews(zblockIPFSHash, zblockObject, blockObject, json){
    if (!document.querySelector('#news-'+zblockIPFSHash)){
        var newsSectionDivElement = document.querySelector('#news-section');
        var articleContainerElement = {
            element:"article",
            id:`news-${zblockIPFSHash}`,
            innerHTML: [
                { element:"a", innerText : json.title, href : '#news-'+zblockIPFSHash },
                { element:"span", innerText : ' '},
                { element:"a", innerText:'[permalink]', target: '_blank', href:'https://news.arching-kaos.net/?from_zblock='+zblockIPFSHash },
                { element:"p", innerText:`zblock: ${zblockIPFSHash}` },
                { element:"p", innerText:"Published: " + new Date(blockObject.timestamp*1000) },
                { element:"p", innerText:"Contributor: " + getNicknameAssossiatedWithGPG(blockObject.gpg) },
                { element:"hr" }
            ]
        };
        makeElement(articleContainerElement, newsSectionDivElement);
        if(json.ipfs){
            archingKaosFetchText(getIPFSURL(json.ipfs), getFullText,[`#news-${zblockIPFSHash}`]);
        }
        if (document.querySelector("#news-sec-not-found")) document.querySelector("#news-sec-not-found").hidden=true;
        makeElement({ element:"hr"}, newsSectionDivElement);
    }
    if (!document.querySelector('#news-preview-'+zblockIPFSHash)){
        var newsSectionDivElement = document.querySelector('.preview');
        var button = {
            element:'button',
            className:'read-more-button',
            // innerText:`${blockObject.action.split('/')[0]}-${zblockIPFSHash} 📖`,
            innerText:`Read more`,
            onclick: `showResult("${blockObject.action.split('/')[0]}-${zblockIPFSHash}")`
        }
        var articleContainerElement = {
            element:"article",
            id:`news-preview-${zblockIPFSHash}`,
            innerHTML: [
                { element:"a", innerText : json.title, href : '#news-'+zblockIPFSHash },
                { element:"span", innerText : ' '},
                { element:"a", innerText:'[permalink]', target: '_blank', href:'https://news.arching-kaos.net/?from_zblock='+zblockIPFSHash },
                { element:"p", innerText:"Published: " + new Date(blockObject.timestamp*1000) },
                { element:"p", innerText:"Contributor: " + getNicknameAssossiatedWithGPG(blockObject.gpg) },
                button,
                { element:"hr" }
            ]
        };
        makeElement(articleContainerElement, newsSectionDivElement);
        if(json.ipfs){
            archingKaosFetchText(getIPFSURL(json.ipfs), getPreviewText, [`#news-preview-${zblockIPFSHash}`, button]);
        }
        makeElement({ element:"hr"}, newsSectionDivElement);
    }
}
// @license-end