From 21b201fd9d131c633e15826445d6e115f57e71fc Mon Sep 17 00:00:00 2001 From: cyber-dream Date: Sat, 29 Apr 2023 15:02:25 +0300 Subject: [PATCH] init blog render via files --- main.go | 22 +++++++++++++++++++--- resources/sys/blog-viewer/blog-viewer.js | 1 + resources/wde.js | 6 +++--- templates/blog-viewer/mobile-app.tmpl | 14 ++++++++------ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 457cfdc..0ee1b1b 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ func main() { persPropsApp := personalprops.NewPersPropsApp() finderApp := finder.FinerApplication{} imgViewerApp := imgviewer.NewImgViewerApp() - blogViewerApp := blogviewer.NewBlogViewerApp() + blogViewerApp := blogviewer.NewBlogViewerApp(webfs) appsStorage := websiteapp.ApplicationsStorage{ Apps: map[string]websiteapp.WebDEApplication{}, } @@ -221,13 +221,29 @@ func main() { } blogViewerRoute := app.Group("blog-viewer") { + blogViewerRoute.GET("writeMockBlog", func(ctx *gin.Context) { + path := ctx.Query("path") + if path == "" { + ctx.JSON(http.StatusBadRequest, "no path provided") + return + } + blogViewerApp.WriteMock(path) + ctx.JSON(http.StatusOK, "OK") + }) + blogViewerRoute.GET("render", func(ctx *gin.Context) { isMobileParam := ctx.Query("isMobile") + path := ctx.Query("path") + if path == "" { + ctx.JSON(http.StatusBadRequest, "no path provided") + return + } + isMobile := isMobileParam == "true" if isMobile { - ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", blogViewerApp.Render(isMobile)) + ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", blogViewerApp.Render(path, isMobile)) } else { - ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", blogViewerApp.Render(isMobile)) + ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", blogViewerApp.Render(path, isMobile)) } }) diff --git a/resources/sys/blog-viewer/blog-viewer.js b/resources/sys/blog-viewer/blog-viewer.js index 2f61074..b905557 100644 --- a/resources/sys/blog-viewer/blog-viewer.js +++ b/resources/sys/blog-viewer/blog-viewer.js @@ -9,6 +9,7 @@ class BlogViewer{ NewWindow(path){ fetch(`${window.location.origin}/application/${this.appId}/render?` + new URLSearchParams({ isMobile: WebDesktopEnvironment.isMobile, + path: path, })) .then((response) => response.text()) .then((html) => { diff --git a/resources/wde.js b/resources/wde.js index 39efd43..817408d 100644 --- a/resources/wde.js +++ b/resources/wde.js @@ -2,10 +2,10 @@ document.addEventListener('DOMContentLoaded', function() { // console.log(window.screen.width) wde = new WebDesktopEnvironment if (!WebDesktopEnvironment.isMobile){ - WebDesktopEnvironment.Open("finder", ["kek"]) - WebDesktopEnvironment.Open("personal-properties", ["kek"]) + WebDesktopEnvironment.Open("finder", ["/home/user/"]) + // WebDesktopEnvironment.Open("personal-properties", ["kek"]) } else { - WebDesktopEnvironment.Open("blog-viewer", ["kek"]) + WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"]) } diff --git a/templates/blog-viewer/mobile-app.tmpl b/templates/blog-viewer/mobile-app.tmpl index db5e1d2..4ef60f2 100644 --- a/templates/blog-viewer/mobile-app.tmpl +++ b/templates/blog-viewer/mobile-app.tmpl @@ -1,14 +1,16 @@ {{ define "blog-viewer/mobile-app.tmpl" }}
- Test header + {{.header}}
{{ range $block := .blocks }} -
- {{ range $data := $block.Data }} - {{$data}} - {{ end }} -
+
+ {{ range $data := $block.Data }} +
+ {{$data}} +
+ {{ end }} +
{{ end }}
{{ end }}