From b1ce3afb99879ee4c4318b8f91a612483655f650 Mon Sep 17 00:00:00 2001 From: ndu Date: Sat, 17 Aug 2024 17:51:55 +0100 Subject: [PATCH] chore(fix): render article --- .github/workflows/deploy.yml | 33 ------- .gitignore | 3 +- research/src/pages/[id].astro | 38 ++++---- .../pages/{ => categories}/[category].astro | 2 +- research/src/pages/index.astro | 81 ++++++++---------- server/db.sqlite3 | Bin 311296 -> 311296 bytes 6 files changed, 64 insertions(+), 93 deletions(-) delete mode 100644 .github/workflows/deploy.yml rename research/src/pages/{ => categories}/[category].astro (96%) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index df1b393..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Deploy - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - - name: Copy repository contents via scp - uses: appleboy/scp-action@master - env: - HOST: ${{ secrets.HOST }} - USERNAME: ${{ secrets.USERNAME }} - PORT: ${{ secrets.PORT }} - KEY: ${{ secrets.SSHKEY }} - PASS: ${{ secrets.PASS }} - with: - source: "." - target: "/var/www/2077-CMS" - - - name: Executing remote command - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.HOST }} - USERNAME: ${{ secrets.USERNAME }} - PORT: ${{ secrets.PORT }} - KEY: ${{ secrets.SSHKEY }} - PASS: ${{ secrets.PASS }} - script: ls \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0833ed3..aea162d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ vpsSetup.md .DS_Store test.rest db.sqlite3 -old-backup-db.sqlite3 \ No newline at end of file +old-backup-db.sqlite3 + diff --git a/research/src/pages/[id].astro b/research/src/pages/[id].astro index 8d6fc0f..b6c76d1 100644 --- a/research/src/pages/[id].astro +++ b/research/src/pages/[id].astro @@ -30,8 +30,14 @@ try { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } - article = await response.json(); - console.log("Article data:", article); + const data = await response.json(); + + if (data && data.success && data.data) { + article = data as Article; + + } else { + throw new Error("Invalid article data"); + } } catch (error) { console.error("Error fetching article:", error); } @@ -39,35 +45,37 @@ try {
Back { - article?.data ? ( + article ? (
-

{article.data.title}

-

{article.data.summary}

+

{article.data?.title}

+

{article.data?.summary}

-
+
) : ( diff --git a/research/src/pages/[category].astro b/research/src/pages/categories/[category].astro similarity index 96% rename from research/src/pages/[category].astro rename to research/src/pages/categories/[category].astro index 0508ac9..2edd167 100644 --- a/research/src/pages/[category].astro +++ b/research/src/pages/categories/[category].astro @@ -1,5 +1,5 @@ --- -import Layout from "../layouts/Layout.astro"; +import Layout from "../../layouts/Layout.astro"; interface Category { name: string; diff --git a/research/src/pages/index.astro b/research/src/pages/index.astro index 643896a..541057c 100644 --- a/research/src/pages/index.astro +++ b/research/src/pages/index.astro @@ -2,60 +2,55 @@ import Layout from "../layouts/Layout.astro"; interface Category { -name: string; + name: string; } interface Article { -id: string; -title: string; -authors: { username: string }[]; -content: string; -views: string; -summary: string; -categories: Category[]; -thumb: string; + id: string; + title: string; + authors: { username: string }[]; + content: string; + views: string; + summary: string; + categories: Category[]; + thumb: string; } let articles: Article[] = []; try { -const response = await fetch("http://127.0.0.1:8000/api/articles"); -articles = await response.json(); + const response = await fetch("http://127.0.0.1:8000/api/articles"); + articles = await response.json(); } catch (error) { -console.error(error); + console.error(error); } --- -
-
    -{ -articles.map((article: Article) => ( -
  • - - -

    {article.title}

    -<> -

    {article.summary}

    -Read post - -
  • -)) -} -
-
-
\ No newline at end of file +
+
    + { + articles.map((article: Article) => ( +
  • + + +

    {article.title}

    + <> +

    {article.summary}

    + Read post + +
  • + )) + } +
+
+ diff --git a/server/db.sqlite3 b/server/db.sqlite3 index 6f283a68ae9179b5d19bf456caa3399c8c14e154..2ef21ff10922f433f6dbda4883918f6b38c7a46a 100644 GIT binary patch delta 108 zcmV-y0F(cKfD?d#6ObDL9FZJD1snh_c8P&xg=7JRWCFEh1EP-1`mNi2@Fj^K_ep-BU1<$GnaAy0w9-;mIHj3pOpdyw-A>DB?bWs Rw>F&v36TLCw?Hlgz>x