Skip to content

Commit

Permalink
127 style individual blog post (#250)
Browse files Browse the repository at this point in the history
* style(frontend): 💄 Fit content into blogcard and add image

* style(frontend): 💄 Make small styling changes and remove subtitle from Strapi

* feat(frontend): ✨ add shareButtons component for blog sharing

* feat(frontend): ✨ Remove card from blog, and add functioning share functionality to blog. Also remove title and coverimage from individual blog post

* fix(frontend): 🐛 remove image and host url from article slug page

* fix(frontend): 🐛 remove next-share from root package and add to frontend package

* fix(frontend): fix eslint unused variable error

* fix(frontend): fix prettier

---------

Co-authored-by: Jakob Grøtan Gregusson <55840686+Jakobgg1243@users.noreply.github.com>
Co-authored-by: Jakob Grøtan Gregusson <jakobgg@stud.ntnu.no>
  • Loading branch information
3 people authored and GitHub committed Apr 10, 2024
1 parent aff0771 commit 12dace8
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 58 deletions.
6 changes: 1 addition & 5 deletions backend/src/api/article/content-types/article/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@
},
"pluginOptions": {},
"attributes": {
"title": {
"previewCardTitle": {
"type": "string",
"required": true,
"unique": true
},
"slug": {
"type": "uid",
"targetField": "title",
"required": true
},
"subtitle": {
"type": "string"
},
"datePublished": {
"type": "date",
"required": true
Expand Down
5 changes: 2 additions & 3 deletions backend/types/generated/contentTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,8 @@ export interface ApiArticleArticle extends Schema.CollectionType {
draftAndPublish: true;
};
attributes: {
title: Attribute.String & Attribute.Required & Attribute.Unique;
slug: Attribute.UID<'api::article.article', 'title'> & Attribute.Required;
subtitle: Attribute.String;
previewCardTitle: Attribute.String & Attribute.Required & Attribute.Unique;
slug: Attribute.UID & Attribute.Required;
datePublished: Attribute.Date & Attribute.Required;
coverImage: Attribute.Media;
body: Attribute.Blocks & Attribute.Required;
Expand Down
37 changes: 37 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"lucide-react": "^0.314.0",
"luxon": "^3.4.4",
"next": "14.1.0",
"next-share": "^0.27.0",
"next-themes": "^0.2.1",
"node-geometry-library": "^1.2.6",
"ol": "^8.2.0",
Expand Down
13 changes: 4 additions & 9 deletions frontend/src/__generated__/gql.ts

Large diffs are not rendered by default.

25 changes: 7 additions & 18 deletions frontend/src/__generated__/graphql.ts

Large diffs are not rendered by default.

27 changes: 13 additions & 14 deletions frontend/src/app/blog/[articleSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { BlocksContent } from "@strapi/blocks-react-renderer";
import BlockRendererClient from "@/components/BlockRendererClient";
import { gql } from "@/__generated__/gql";
import { getClient } from "@/lib/ApolloClient";
import ShareButtons from "@/components/ShareButtons";

const STRAPI_URL = process.env.STRAPI_URL;

const GET_ARTICLE_BY_SLUG = gql(
`query ArticleWithSlug($articlesFilters: ArticleFiltersInput) {
articles(filters: $articlesFilters) {
data {
id
attributes {
author {
data {
Expand All @@ -34,8 +37,7 @@ const GET_ARTICLE_BY_SLUG = gql(
}
}
datePublished
subtitle
title
previewCardTitle
}
}
}
Expand Down Expand Up @@ -81,12 +83,12 @@ export default async function Page({
const content: BlocksContent = article?.attributes?.body ?? [];

return (
<>
<div className="flex flex-col items-center gap-4">
<h1 className="text-4xl font-extrabold">
{article?.attributes?.title}
</h1>
<div className="flex flex-row items-center justify-center gap-1">
<div className="flex flex-col items-center gap-4">
<div className="w-1/2">
<BlockRendererClient content={content} />
</div>
<div className="flex w-1/2 flex-row items-center gap-1">
<div className="flex flex-1 justify-start gap-1">
{avatarURL && (
<Avatar className="">
<AvatarImage src={avatarURL} />
Expand All @@ -104,13 +106,10 @@ export default async function Page({
<p>{datePublished}</p>
</div>
</div>
<p className="text-sm text-muted-foreground">
{article?.attributes?.subtitle}{" "}
</p>
<div className="w-1/2">
<BlockRendererClient content={content} />
<div className="flex flex-1 justify-end gap-1">
<ShareButtons slug={params.articleSlug} />
</div>
</div>
</>
</div>
);
}
8 changes: 2 additions & 6 deletions frontend/src/app/satellites/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ export default async function Satellites() {
let previewImage =
satellite?.attributes?.previewImage?.data
?.attributes?.url;
if (
STRAPI_URL &&
previewImage != undefined
) {
previewImage =
STRAPI_URL + previewImage;
if (STRAPI_URL && previewImage != undefined) {
previewImage = STRAPI_URL + previewImage;
}
let satelliteName =
satellite?.attributes?.name ?? "";
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/components/ShareButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use client";

import {
FacebookShareButton,
FacebookIcon,
LinkedinShareButton,
LinkedinIcon,
TwitterShareButton,
TwitterIcon,
} from "next-share";

export default function ShareButtons({ slug }: { slug: String }) {
return (
<>
<FacebookShareButton
url={`http://web.hypso.ies.ntnu.no:3000/blog/${slug}`}
>
<FacebookIcon size={32} round />
</FacebookShareButton>
<LinkedinShareButton
url={`http://web.hypso.ies.ntnu.no:3000/blog/${slug}`}
>
<LinkedinIcon size={32} round />
</LinkedinShareButton>
<TwitterShareButton
url={`http://web.hypso.ies.ntnu.no:3000/blog/${slug}`}
>
<TwitterIcon size={32} round />
</TwitterShareButton>
</>
);
}
5 changes: 2 additions & 3 deletions frontend/src/lib/data/fetchArticleInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ query GET_ARTICLES($pagination: PaginationArg, $filters: ArticleFiltersInput) {
}
}
}
title
previewCardTitle
datePublished
body
coverImage {
Expand All @@ -39,7 +39,6 @@ query GET_ARTICLES($pagination: PaginationArg, $filters: ArticleFiltersInput) {
createdAt
publishedAt
slug
subtitle
Tag
}
}
Expand Down Expand Up @@ -122,7 +121,7 @@ export default async function fetchArticlePages({
}
let content: BlocksContent = article?.attributes?.body ?? [];

const title: string | undefined = article?.attributes?.title;
const title: string | undefined = article?.attributes?.previewCardTitle;

for (const block of content) {
if (block.type === "paragraph") {
Expand Down
83 changes: 83 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12dace8

Please sign in to comment.