diff --git a/UI/Base/Paragraph.ts b/UI/Base/Paragraph.ts new file mode 100644 index 000000000..da5714257 --- /dev/null +++ b/UI/Base/Paragraph.ts @@ -0,0 +1,33 @@ +import BaseUIElement from "../BaseUIElement"; + +export class Paragraph extends BaseUIElement { + public readonly content: (string | BaseUIElement); + + constructor(html: (string | BaseUIElement)) { + super(); + this.content = html ?? ""; + } + + + AsMarkdown(): string { + let c:string ; + if(typeof this.content !== "string"){ + c = this.content.AsMarkdown() + }else{ + c = this.content + } + return "\n\n"+c+"\n\n" + } + + protected InnerConstructElement(): HTMLElement { + const e = document.createElement("p") + if(typeof this.content !== "string"){ + e.appendChild(this.content.ConstructElement()) + }else{ + e.innerHTML = this.content + } + return e; + } + + +} \ No newline at end of file diff --git a/UI/Wikipedia/WikidataPreviewBox.ts b/UI/Wikipedia/WikidataPreviewBox.ts index 1e6db1ca3..ca86a70a9 100644 --- a/UI/Wikipedia/WikidataPreviewBox.ts +++ b/UI/Wikipedia/WikidataPreviewBox.ts @@ -28,12 +28,12 @@ export default class WikidataPreviewBox extends VariableUiElement { requires: WikidataPreviewBox.isHuman, property: "P21", display: new Map([ - ['Q6581097', () => Svg.gender_male_ui().SetStyle("width: 1rem; height: auto")], - ['Q6581072', () => Svg.gender_female_ui().SetStyle("width: 1rem; height: auto")], - ['Q1097630', () => Svg.gender_inter_ui().SetStyle("width: 1rem; height: auto")], - ['Q1052281', () => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transwomen'*/], - ['Q2449503', () => Svg.gender_trans_ui().SetStyle("width: 1rem; height: auto")/*'transmen'*/], - ['Q48270', () => Svg.gender_queer_ui().SetStyle("width: 1rem; height: auto")] + ['Q6581097', () => Svg.gender_male_svg().SetStyle("width: 1rem; height: auto")], + ['Q6581072', () => Svg.gender_female_svg().SetStyle("width: 1rem; height: auto")], + ['Q1097630', () => Svg.gender_inter_svg().SetStyle("width: 1rem; height: auto")], + ['Q1052281', () => Svg.gender_trans_svg().SetStyle("width: 1rem; height: auto")/*'transwomen'*/], + ['Q2449503', () => Svg.gender_trans_svg().SetStyle("width: 1rem; height: auto")/*'transmen'*/], + ['Q48270', () => Svg.gender_queer_svg().SetStyle("width: 1rem; height: auto")] ]) }, { @@ -84,7 +84,7 @@ export default class WikidataPreviewBox extends VariableUiElement { let link = new Link( new Combine([ wikidata.id, - Svg.wikidata_ui().SetStyle("width: 2.5rem").SetClass("block") + Svg.wikidata_svg().SetStyle("width: 2.5rem").SetClass("block") ]).SetClass("flex"), Wikidata.IdToArticle(wikidata.id), true)?.SetClass("must-link") diff --git a/UI/Wikipedia/WikipediaBox.ts b/UI/Wikipedia/WikipediaBox.ts index b1a28fd46..e096ceee7 100644 --- a/UI/Wikipedia/WikipediaBox.ts +++ b/UI/Wikipedia/WikipediaBox.ts @@ -14,9 +14,14 @@ import {FixedUiElement} from "../Base/FixedUiElement"; import Translations from "../i18n/Translations"; import Link from "../Base/Link"; import WikidataPreviewBox from "./WikidataPreviewBox"; +import {Paragraph} from "../Base/Paragraph"; export default class WikipediaBox extends Combine { + public static configuration = { + onlyFirstParagaph: false, + addHeader: false + } constructor(wikidataIds: string[]) { @@ -27,9 +32,9 @@ export default class WikipediaBox extends Combine { const page = pages[0] mainContents.push( new Combine([ - new Combine([Svg.wikipedia_ui() - .SetStyle("width: 1.5rem").SetClass("inline-block mr-3"), page.titleElement]) - .SetClass("flex"), + new Combine([ + Svg.wikipedia_svg().SetStyle("width: 1.5rem").SetClass("inline-block mr-3"), + page.titleElement]).SetClass("flex"), page.linkElement ]).SetClass("flex justify-between align-middle"), ) @@ -52,7 +57,7 @@ export default class WikipediaBox extends Combine { }), 0, { - leftOfHeader: Svg.wikipedia_ui().SetStyle("width: 1.5rem; align-self: center;").SetClass("mr-4"), + leftOfHeader: Svg.wikipedia_svg().SetStyle("width: 1.5rem; align-self: center;").SetClass("mr-4"), styleHeader: header => header.SetClass("subtle-background").SetStyle("height: 3.3rem") } ) @@ -141,7 +146,7 @@ export default class WikipediaBox extends Combine { return new Title(pagetitle, 3) } //return new Title(Translations.t.general.wikipedia.wikipediaboxTitle.Clone(), 2) - return new Title(wikidataId, 3) + return new Link(new Title(wikidataId, 3), "https://www.wikidata.org/wiki/"+wikidataId, true) })) @@ -150,13 +155,13 @@ export default class WikipediaBox extends Combine { const [pagetitle, language] = state if (pagetitle === "no page") { const wd = state[1] - return new Link(Svg.pop_out_ui().SetStyle("width: 1.2rem").SetClass("block "), + return new Link(Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block "), "https://www.wikidata.org/wiki/" + wd.id , true) } const url = `https://${language}.wikipedia.org/wiki/${pagetitle}` - return new Link(Svg.pop_out_ui().SetStyle("width: 1.2rem").SetClass("block "), url, true) + return new Link(Svg.pop_out_svg().SetStyle("width: 1.2rem").SetClass("block "), url, true) } return undefined })) @@ -172,15 +177,14 @@ export default class WikipediaBox extends Combine { /** * Returns the actual content in a scrollable way - * @param pagename - * @param language - * @private */ private static createContents(pagename: string, language: string, wikidata: WikidataResponse): BaseUIElement { - const htmlContent = Wikipedia.GetArticle({ + const wpOptions = { pageName: pagename, - language: language - }) + language: language, + firstParagraphOnly: WikipediaBox.configuration.onlyFirstParagaph + } + const htmlContent = Wikipedia.GetArticle(wpOptions) const wp = Translations.t.general.wikipedia const quickFacts = WikidataPreviewBox.QuickFacts(wikidata); const contents: UIEventSource = htmlContent.map(htmlContent => { @@ -189,7 +193,20 @@ export default class WikipediaBox extends Combine { return new Loading(wp.loading.Clone()) } if (htmlContent["success"] !== undefined) { - return new FixedUiElement(htmlContent["success"]).SetClass("wikipedia-article") + let content: BaseUIElement = new FixedUiElement(htmlContent["success"]); + if(WikipediaBox.configuration.addHeader){ + content = new Combine( + [ + new Paragraph( + new Link(wp.fromWikipedia, Wikipedia.getPageUrl(wpOptions), true), + ), + new Paragraph( + content + ) + ] + ) + } + return content.SetClass("wikipedia-article") } if (htmlContent["error"]) { console.warn("Loading wikipage failed due to", htmlContent["error"]) diff --git a/langs/en.json b/langs/en.json index 4b6f74a0e..1711702fa 100644 --- a/langs/en.json +++ b/langs/en.json @@ -247,6 +247,7 @@ "createNewWikidata": "Create a new Wikidata item", "doSearch": "Search above to see results", "failed": "Loading the Wikipedia entry failed", + "fromWikipedia": "From Wikipedia, the free encyclopedia", "loading": "Loading Wikipedia...", "noResults": "Nothing found for {search}", "noWikipediaPage": "This Wikidata item has no corresponding Wikipedia page yet.",