#!/usr/bin/env -S node --experimental-fetch const fs = require('fs'); const JSDOM = require('jsdom').JSDOM; const ConfigParser = require('./Lib/config-ini-parser').ConfigIniParser; const BlogURL = 'https://listed.to/@u8'; // Full base URL of the Listed blog (any server) const SiteName = 'sitoctt'; //const DefaultMode = 'Include' // 'Include' or 'Exclude' | Not implemented const PostsFileDate = true; // Append dates (YYYY-MM-DD) to posts file names let Replacements = { // Format: { ReplaceWithString: [ToFindString] } "

[:HNotesRefsHTML:]

": "

🏷️ Note e Riferimenti

", '
': ['

', '
\n
'], '"> { if (fs.existsSync(Path)) { return fs.readFileSync(Path, 'utf8'); }; }; const TryMkdirSync = Path => { if (!fs.existsSync(Path)) { return fs.mkdirSync(Path, {recursive: true}); }; }; const GetPath = URL => { if (URL.startsWith('http://') || URL.startsWith('https://')) { URL = URL.split('/').slice(3).join('/'); }; return URL; }; const GetFragHTML = Frag => { let Dom = new JSDOM(''); Dom.window.document.body.appendChild(Frag); return Dom.window.document.body.innerHTML.trim(); }; const CSSFirstTokenSelector = Select => { return Select.trim().replaceAll('.', '').replaceAll(',', '').split(' ')[0]; }; const CheckDownsync = Body => { if (Body) { const Lines = Body.trim().toLowerCase().split('\n'); for (let i=0; i {return i != ''}); if (Tokens[1] == '%' && Tokens[2] == 'downsync' && [':', '='].includes(Tokens[3])) { if (['false', 'disabled', 'off', 'no', '0'].includes(Tokens[4])) { return false; } else if (Tokens[4].startsWith('/')) { return Line.substring(Line.indexOf('/', 2)); }; }; }; }; }; return true; }; const GetLinkElem = Dom => { let Elem; Elem = Dom.querySelector(`.Mirror-${SiteName}`); if (!Elem) { Elem = Dom.querySelector(`.Mirror-${SiteName}-Include`); }; return Elem; }; const ParseMeta = Raw => { let Mid = {'Meta': '', 'Macros': ''}; let Data = {'Meta': {}, 'Macros': {}}; const Lines = Raw.trim().split('\n'); for (let i=0; i { let Str = ''; const Types = ['Meta', 'Macros']; for (let i=0; i { let ContentDom, LinkPath; let Post = {'Meta': {}, 'Macros': {}}; Post.Meta.Title = PostSrc.title; Post.Meta.CreatedOn = PostSrc.created_at.split('T')[0]; Post.Content = PostSrc.rendered_text; console.log(`[I] => [${Post.Meta.CreatedOn}] ${Post.Meta.Title}`); ContentDom = JSDOM.fragment(Post.Content); // Handle .MetadataBlock elements let MetadataBlocks = ContentDom.querySelectorAll(MetadataBlockSelect); for (let i=0; i${Post.Meta.HTMLTitle ? Post.Meta.HTMLTitle : Post.Meta.Title} ${Post.Content} `); } else if (Output == 'stdout') { console.log(Post.Content); }; }; const Main = _ => { console.log('[I] Downloading...'); fetch(`${BlogURL}/all`).then(Response => Response.text()).then(Data => { console.log('[I] Parsing...'); const Elem = JSDOM.fragment(Data).querySelector('script[data-component-name="AuthorAll"]'); const Posts = JSON.parse(Elem.childNodes[0].data).posts; for (let i=0; i { console.log('[I] Testing...'); fetch(TestURL).then(Response => Response.text()).then(Data => { const Elem = JSDOM.fragment(Data).querySelector('script[data-component-name="PostShow"]'); const Post = JSON.parse(Elem.childNodes[0].data).post; HandlePost(Post, 'stdout'); }); }; Main(); //Test();