Skip to content

Commit c21ad56

Browse files
committed
fixed Project og title added in ssr
1 parent df50578 commit c21ad56

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

server/controllers/project.controller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,14 @@ export async function projectExists(projectId) {
165165
*/
166166
export async function projectForUserExists(username, projectId) {
167167
const user = await User.findByUsername(username);
168-
if (!user) return false;
168+
if (!user) return { success: false };
169169
const project = await Project.findOne({
170170
user: user._id,
171171
$or: [{ _id: projectId }, { slug: projectId }]
172172
});
173-
return project != null;
173+
return project != null
174+
? { success: true, projectName: project.name }
175+
: { success: false };
174176
}
175177

176178
/**

server/views/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import get404Sketch from './404Page';
22

3-
export function renderIndex() {
3+
export function renderIndex(username , projectName) {
44
const assetsManifest = process.env.webpackAssets && JSON.parse(process.env.webpackAssets);
55
return `
66
<!DOCTYPE html>
@@ -10,7 +10,7 @@ export function renderIndex() {
1010
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1111
<meta name="keywords" content="p5.js, p5.js web editor, web editor, processing, code editor" />
1212
<meta name="description" content="A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners." />
13-
<title>p5.js Web Editor</title>
13+
<title>${`${username ? `${projectName} by ${username} -`: ""}`}p5.js Web Editor</title>
1414
${process.env.NODE_ENV === 'production' ? `<link rel='stylesheet' href='${assetsManifest['/app.css']}' />` : ''}
1515
<link href='https://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'>
1616
<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
@@ -54,11 +54,11 @@ export function renderIndex() {
5454
* @param {import('express').e.Response} res
5555
* @param {boolean} [exists]
5656
*/
57-
export default function sendHtml(req, res, exists = true) {
58-
if (!exists) {
57+
export default function sendHtml(req, res, exists = {success:true}) {
58+
if (!exists.success) {
5959
res.status(404);
6060
get404Sketch((html) => res.send(html));
6161
} else {
62-
res.send(renderIndex());
62+
res.send(renderIndex(req.params.username, exists.projectName));
6363
}
6464
};

0 commit comments

Comments
 (0)