OcttKB Cross-Repo Sync (HTML to Raw)

This commit is contained in:
2023-07-23 13:33:31 +00:00
parent 0cfc51da4e
commit 49c7acc7f3
971 changed files with 50 additions and 29 deletions

View File

@@ -0,0 +1,67 @@
/*\
See [[$:/Macros/MediaWiki]] for usage of this macro.
Note: source must always be credited, and thus it's not ideal to use this macro directly. Please use the <<MediaWiki>> wrapper macro instead, as it provides a link to the source automatically. (This feature is implemented in its own non-JS macro to make at least the URL show on static wiki exports.)
\*/
(function(){
"use strict";
exports.name = "MediaWikiEmbedInternal";
exports.params = [
{name: "Article"},
{name: "Domain"},
{name: "Sections"},
];
exports.run = function(Article, Domain, Sections) {
try {
let Text;
Sections = parseInt(Sections) || 0;
Domain = $OcttKB.MediaWiki.MkDomain(Domain);
const Req = new XMLHttpRequest();
Req.open('GET', Domain + '/w/api.php?action=query&formatversion=2&prop=extracts&format=json&origin=*&titles=' + Article, false);
Req.send();
Text = JSON.parse(Req.responseText).query.pages[0].extract;
if (!Text) {
Text = '<p>An error occurred while trying to extract the content. Close and reopen this <i>tiddler</i> to retry, or click the link to open the source in a new tab.</p>'
};
Text = Text.replaceAll('\n', '').replaceAll('<p class="mw-empty-elt"></p>', '');
if (Sections != 0) {
for (let i=1; i<=6; i++) {
Text = Text.replaceAll(`</p><h${i}>`, `</p><!--:PARAGRAPH:--->\n<h${i}>`);
};
Text = Text.replaceAll(`</p><p>`, `</p><!--:PARAGRAPH:---><p>`);
//Text = Text.split('<!--:PARAGRAPH:--->').slice(0, Max+1).join('');
//Text = Text.split('<p>').slice(0, Max+1).join('<p>');
if (Sections < 0) {
Sections = 0;
};
Text = Text.split('<!--:PARAGRAPH:--->').slice(0, Sections).join('');
//Text += '<p>[...]</p>'
};
/*
Sections = Sections.split(' ');
for (let i=0; i<Sections.length; i++) {
const Sec = Sections[i];
if (Sec) {
const Ind = Sec.toLowerCase()[0];
const Val = Sec.substring(1);
if (Ind == 'p' || Ind == 's') {
if (Ind == 'p') {
const Sep = '<!--:PARAGRAPH:--->';
} else
if (Ind == 's') {
const Sep = '<!--:SECTION:--->';
};
Text = Text.split(Sep).slice(0, Val).join('');
} else
if (Ind == '#') {
};
};
};
*/
return Text;
} catch(e) {
return $OcttKB.ErrAtLine(e);
};
}})();

View File

@@ -0,0 +1,10 @@
Note: source must always be credited, and thus it's not ideal to use this macro directly. Please use the <<MediaWiki>> wrapper macro instead, as it provides a link to the source automatically. (This feature is implemented in its own non-JS macro to make at least the URL show on static wiki exports.)
See [[$: /Macros/MediaWiki]] for usage of this macro.
created: 20230108190340455
creator: Octt
modified: 20230429192152268
modifier: Octt
module-type: macro
tags:
title: $:/Macros/MediaWiki/EmbedInternal.js
type: application/javascript

View File

@@ -0,0 +1,32 @@
/*\
Get the cover image from a MediaWiki article.
[<<]MediaWikiGetCover "Article" "Full Domain OR Wikipedia Subdomain" "Manual URL OR NULL"[>>]
\*/
(function(){
"use strict";
exports.name = "MediaWikiGetCover";
exports.params = [
{name: "Article"},
{name: "Domain"},
{name: "URL"},
];
exports.run = function(Article, Domain, URL) {
try {
if (!URL || URL && !$OcttKB.Options.Nulls.includes(URL.toLowerCase())) {
let File;
Domain = $OcttKB.MediaWiki.MkDomain(Domain);
const Req = new XMLHttpRequest();
Req.open('GET', Domain + '/w/api.php?action=query&prop=pageimages&format=json&piprop=original&origin=*&titles=' + Article, false);
Req.send();
File = Object.values(JSON.parse(Req.responseText).query.pages)[0];
if (File && File.original && File.original.source) {
return `<img src="${File.original.source}">`;
};
};
return '';
} catch(e) {
return $OcttKB.ErrAtLine(e);
};
}})();

View File

@@ -0,0 +1,8 @@
created: 20230112154435120
creator: Octt
modified: 20230124213845342
modifier: Octt
module-type: macro
tags:
title: $:/Macros/MediaWiki/GetCover.js
type: application/javascript

View File

@@ -0,0 +1,50 @@
created: 20230110102736164
creator: Octt
modified: 20230305223746772
modifier: Octt
tags: $:/tags/Macro
title: $:/Macros/MediaWiki/Main
<!--
[<<]MediaWiki[>>]
| Embed sections of an article from a MediaWiki server.
| [<<]MediaWiki "Article" "Full Domain OR Wikipedia Subdomain" "Section Filtering" "Cover Media"[>>]
--->
\define MediaWiki(Article Domain Sections Cover)
<div class="MediaWikiEmbed MediaWikiEmbedBlock">
<div class="EmbedFrom MediaWikiEmbedFrom">
From <$set name="FullDomain" filter="[[$Domain$]regexp[\.]then[$Domain$]else[$Domain$.Wikipedia.org]]">
<$macrocall $name="ExtMediaWikiAnchor" Article="$Article$" Domain=<<FullDomain>>/>
</$set>
</div>
<div class="MediaWikiEmbedCover">
<<MediaWikiGetCover "$Article$" "$Domain$" "$Cover$">>
</div>
<div class="MediaWikiEmbedContent">
<<MediaWikiEmbedInternal "$Article$" "$Domain$" "$Sections$">>
</div>
</div>
\end
\define ExtMediaWikiAnchor(Article, Domain) [[$Domain$/$Article$|https://$Domain$/wiki/$Article$]]
\define WikipediaLink(Article, Subdomain:"en") [[$Article$|https://$Subdomain$.wikipedia.org/wiki/$Article$]]
\define WikipediaLink-(Article, Subdomain:"en") [[$Article$ - Wikipedia|https://$Subdomain$.wikipedia.org/wiki/$Article$]]
<!--
<a href={{{[[$Article$]search-replace:g[ ],[_]prepend[https://$Subdomain$.wikipedia.org/]]}}}>$Article$</a>
-->
\define WikipediaFrame(Article, Subdomain:"en")
<<iFrame "https://$Subdomain$.m.wikipedia.org/wiki/$Article$">>
\end
\define wikipediaframe(Article, Subdomain) <<WikipediaFrame "$Article$" "$Subdomain$">>
\define ^WikipediaFrame(Article, Subdomain, Title:"Wikipedia")
<details class="tw-details">
<summary><strong>$Title$</strong></summary>
<<WikipediaFrame "$Article$" "$Subdomain$">>
</details>
\end
\define ^wikipediaframe(Article, Subdomain, Title) <<^WikipediaFrame "$Article$" "$Subdomain$" "$Title$">>