Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

feat: meta description for profile #9834

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions models/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ const ProfileSchema = new Schema(
min: 2,
max: 256,
},
metaDescription: {
type: String,
required: false,
min: 2,
max: 160,
},
tags: {
type: [String],
default: [],
Expand Down
14 changes: 2 additions & 12 deletions pages/[username].js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useEffect, useState } from "react";
import { IconContext } from "react-icons";
import { FaArrowsRotate, FaEye, FaRegFaceSmileWink } from "react-icons/fa6";
import { remark } from "remark";
import strip from "strip-markdown";
import requestIp from "request-ip";
import { authOptions } from "./api/auth/[...nextauth]";
import { getServerSession } from "next-auth/next";
Expand Down Expand Up @@ -44,14 +42,6 @@ export async function getServerSideProps(context) {

logger.info(`data loaded for username: ${username}`);

try {
const processedBio = await remark().use(strip).process(profile.bio);
profile.cleanBio = processedBio.toString();
} catch (e) {
logger.error(e, `cannot strip markdown for: ${username}`);
profile.cleanBio = profile.bio;
}

// override hiding navbar and footer if custom domain matches
if (
profile.settings?.domain &&
Expand Down Expand Up @@ -87,9 +77,9 @@ export default function User({ data, BASE_URL, isLoggedIn }) {
<>
<PageHead
title={data.name}
description={data.cleanBio}
description={data.metaDescription}
ogTitle={data.name}
ogDescription={data.cleanBio}
ogDescription={data.metaDescription}
ogUrl={`https://biodrop.io/${data.username}`}
ogImage={`https://github.com/${data.username}.png`}
ogType="image/png"
Expand Down
38 changes: 35 additions & 3 deletions pages/account/manage/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import path from "path";
import { authOptions } from "../../api/auth/[...nextauth]";
import { getServerSession } from "next-auth/next";
import { useRef, useState } from "react";
import { remark } from "remark";
import strip from "strip-markdown";

import { clientEnv } from "@config/schemas/clientSchema";
import config from "@config/app.json";
Expand Down Expand Up @@ -38,6 +40,14 @@ export async function getServerSideProps(context) {
profile.name = session.user.name;
}

try {
const processedBio = await remark().use(strip).process(profile.bio);
profile.cleanBio = processedBio.toString();
} catch (e) {
logger.error(e, `cannot strip markdown for: ${username}`);
profile.cleanBio = profile.bio;
}

const filePath = path.join(process.cwd(), "data", username);
let fileExists;
try {
Expand Down Expand Up @@ -65,8 +75,10 @@ export default function Profile({ BASE_URL, profile, fileExists }) {
const [isStatsPublic, setIsStatsPublic] = useState(
profile.isStatsPublic ? true : false,
);
const [bio, setBio] = useState(
profile.bio || "Have a look at my links below...",
const defaultBio = "Have a look at my links below...";
const [bio, setBio] = useState(profile.bio || defaultBio);
const [metaDescription, setMetaDescription] = useState(
profile.metaDescription || profile.cleanBio || defaultBio,
);
const [tags, setTags] = useState(profile.tags || ["EddieHub"]);
const layouts = config.layouts.map((l) => {
Expand Down Expand Up @@ -101,7 +113,15 @@ export default function Profile({ BASE_URL, profile, fileExists }) {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ name, bio, tags, layout, pronoun, isStatsPublic }),
body: JSON.stringify({
name,
bio,
tags,
layout,
pronoun,
isStatsPublic,
metaDescription,
}),
});
const update = await res.json();

Expand Down Expand Up @@ -261,6 +281,18 @@ export default function Profile({ BASE_URL, profile, fileExists }) {
max 32 characters).
</p>
</div>

<div className="col-span-3 sm:col-span-4">
<Textarea
name="metaDescription"
label="Meta Description"
value={metaDescription}
onChange={(e) => setMetaDescription(e.target.value)}
required
minLength="2"
maxLength="160"
/>
</div>
</div>
<div className="mt-3">
<Toggle
Expand Down
2 changes: 2 additions & 0 deletions pages/api/account/manage/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export async function updateProfileApi(
name: data.name,
isStatsPublic: data.isStatsPublic,
bio: data.bio,
metaDescription: data.metaDescription,
pronoun: data.pronoun,
tags: data.tags
.filter((tag) => Boolean(tag.trim()))
Expand All @@ -85,6 +86,7 @@ export async function updateProfileApi(
"layout",
"name",
"bio",
"metaDescription",
"isStatsPublic",
]);
} catch (e) {
Expand Down