diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 98bea0e..fcef306 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,6 +17,7 @@ pages: stage: deploy script: | python3 ./Build.py + mv ./Dist ./public artifacts: paths: - public diff --git a/Build.py b/Build.py index 548e87f..b014922 100755 --- a/Build.py +++ b/Build.py @@ -5,20 +5,25 @@ from pathlib import Path os.chdir(os.path.dirname(os.path.abspath(__file__))) os.makedirs('./Dist', exist_ok=True) -with open('./Friendiiverse.html', 'r') as Base: +os.chdir('./Source') + +with open(f'./Friendiiverse.html', 'r') as Base: Base = Base.read() -def FragReplace(Find, Replace, Pattern='*.*', Folder='./Source/'): +def FragReplace(Find, Replace, Pattern='*.*'): global Base for File in Path('./').rglob(Pattern): + File = str(File) with open(File, 'r') as Frag: - Frag = Replace[0] + Frag.read() + Replace[1] + Frag = Replace.format(File=File, Frag=Frag.read()) for Prefix in ('', './'): - Base = Base.replace(Find[0] + Prefix + str(File) + Find[1], Frag) + File = Prefix + File + Base = Base.replace(Find.format(File=File), Frag) -FragReplace((''), (''), '*.css') -FragReplace((''), (''), '*.js') +FragReplace('', '', '*.css') +FragReplace('', '', '*.js') + +os.chdir('..') with open('./Dist/Friendiiverse.html', 'w') as Build: Build.write(Base) - diff --git a/Source/ApiTransform.js b/Source/ApiTransform.js index f028f7b..7ad46a4 100644 --- a/Source/ApiTransform.js +++ b/Source/ApiTransform.js @@ -19,15 +19,29 @@ var TransSchemas = { }, }; var TransSchemas_ = { - "Note": { - "Author": { - "Mastodon": "Status.account" + "Author": { + "Banner": { + "Mastodon": "header" }, - "Content": { - "Mastodon": "Status.content" + "Picture": { + "Mastodon": "avatar" }, "Url": { - "Mastodon": "Status.url" + "Mastodon": "url" + }, + }, + "Note": { + "Author": { + "Mastodon": "account" + }, + "Content": { + "Mastodon": "content" + }, + "Time": { + "Mastodon": "created_at" + }, + "Url": { + "Mastodon": "url" }, }, }; @@ -42,7 +56,7 @@ var TransParsers = { }, Status(Data) { return JsonTransformA(Data, TransSchemas.Mastodon.Status, TransSchemas.Mastodon); - // return JsonTransformB({Status: Data}, TransSchemas_, TransSchemas_.Note, 'Mastodon'); + //return JsonTransformB(Data, TransSchemas_, TransSchemas_.Note, 'Mastodon'); }, }, }; diff --git a/Source/FakeApi.js b/Source/FakeApi.js index 35bebeb..d13f238 100644 --- a/Source/FakeApi.js +++ b/Source/FakeApi.js @@ -4,3 +4,15 @@ var FakeApi = { //"timelines/public": }, }; + +FakeApi.Mastodon.Account = { + "avatar": "https://picsum.photos/64", + "url": "https://mastodon.example.com/@Tester", +}; + +FakeApi.Mastodon.Status = { + "account": FakeApi.Mastodon.Account, + "content": "
Lorem ipsum dolor sit amet...
", + "created_at": "2023-01-01T13:00:00.123Z", + "url": "https://mastodon.example.com/@Tester/1234567890", +}; diff --git a/Source/Main.js b/Source/Main.js index 3eb4e6d..04a233f 100644 --- a/Source/Main.js +++ b/Source/Main.js @@ -46,17 +46,22 @@ function ApiCall(Data, Proc) { var Req = new XMLHttpRequest(); Req.Proc = Proc; Req.onloadend = function(){ - var Status = String(this.status); + try { + this.responseJson = JSON.parse(this.responseText); + this.responseLog = this.responseJson; + } catch(Ex) { + this.responseLog = this.responseText; + }; if (Data.Call) { Data.Call(this); }; if (HttpCodeGood(this.status)) { - LogDebug([this.status, this.responseText], 'l'); + LogDebug([this.status, this.responseLog], 'l'); if (Data.CallFine) { Data.CallFine(this); }; } else { - LogDebug([this.status, this.responseText], 'e'); + LogDebug([this.status, this.responseLog], 'e'); if (Data.CallFail) { Data.CallFail(this); }; @@ -87,23 +92,29 @@ function DisplayFriendicaTimeline(Timeline) { }}); }; +function ResFetchMastodon(Res) { + var Notes = TransParsers.Mastodon.Status(Res.responseJson); + LogDebug(Notes, 'l'); + CurrTasks[Res.Proc[0]].Return(Notes); +}; + function FetchMastodon(Proc) { - ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: function(Res){ - var Notes = TransParsers.Mastodon.Status(JSON.parse(Res.responseText)); - LogDebug(Notes, 'l'); - CurrTasks[Proc[0]].Return(Notes); - }}, Proc); + if (UseFakeApi) { + ResFetchMastodon({responseJson: [FakeApi.Mastodon.Status], Proc: Proc}); + } else { + ApiCall({Target: "Mastodon", Method: "timelines/public", CallFine: ResFetchMastodon}, Proc); + }; }; function FillTimeline(Notes) { Notes.forEach(function(Note){ - TimelineView.innerHTML += `