From d8c9bde1a563f3cae8ee93cfa0174d621109a7a6 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 14 Nov 2018 23:03:40 -0400 Subject: Specify page titles --- index.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 53426f5..ef79d57 100755 --- a/index.js +++ b/index.js @@ -11,7 +11,7 @@ const readFile = util.promisify(fs.readFile) // General page size. const limit = 20 -const page = async (request, response, text) => { +const page = async (request, response, text, title = 'Scratch') => { const cookies = parseCookies(request) const notificationCount = await getMessageCount(cookies.username) @@ -22,7 +22,7 @@ const page = async (request, response, text) => { - Scratch + ${filterHTML(title)} @@ -264,7 +264,7 @@ const handleRequest = async (request, response) => {

- `) + `, 'Login') } else if (request.method === 'POST') { const { username, token, sessionid, csrftoken } = await getData(request) @@ -279,7 +279,7 @@ const handleRequest = async (request, response) => { return page(request, response, fixWS`

Okay, you're logged in.

- `) + `, 'Logged In') } } @@ -291,7 +291,7 @@ const handleRequest = async (request, response) => {

Are you sure you want to log out?

- `) + `, 'Log Out') } else if (request.method === 'POST') { const { username, token, sessionid, csrftoken } = await getData(request) @@ -302,7 +302,7 @@ const handleRequest = async (request, response) => { return page(request, response, fixWS`

Okay, you've been logged out.

- `) + `, 'Logged Out') } } @@ -310,7 +310,7 @@ const handleRequest = async (request, response) => { if (!cookie.username) { return page(request, response, fixWS`

Sorry, you can't view your notifications until you've logged in.

- `) + `, 'Notifications') } const notifications = await getNotifications(cookie.username, cookie.token, pageNumber) @@ -345,7 +345,7 @@ const handleRequest = async (request, response) => {

You are on page ${pageNumber}. ${notifications.length === limit && `Next`} ${pageNumber > 1 && `Previous`}

- `) + `, 'Notifications') } if (compareArr(urlParts, ['notifications', 'mark-as-read'])) { @@ -370,7 +370,7 @@ const handleRequest = async (request, response) => { response.statusCode = 404 return page(request, response, fixWS` 404. Sorry, that project either doesn't exist or isn't shared. - `) + `, 'Project Not Found') } if (urlParts.length === 2) { @@ -388,7 +388,7 @@ const handleRequest = async (request, response) => { const remixesText = remixes.map(templates.projectThumbnail).join('\n') return page(request, response, fixWS` -

${project.title}

+

${filterHTML(project.title)}

Created by ${templates.user(project.author.username)}.${parentProjectText}

The thumbnail for this project

${project.instructions ? fixWS` @@ -412,12 +412,12 @@ const handleRequest = async (request, response) => {

See all!

` : ''} - `) + `, project.title) } else if (compareArr(urlParts.slice(2), ['remixes'])) { return page(request, response, fixWS`

Remixes of ${filterHTML(project.title)}

${await templates.projectList(`https://api.scratch.mit.edu/projects/${projectID}/remixes`, pathname, pageNumber)} - `) + `, `Remixes of ${project.title}`) } } @@ -429,7 +429,7 @@ const handleRequest = async (request, response) => { response.statusCode = 404 return page(request, response, fixWS` 404. Sorry, that user doesn't exist. - `) + `, 'User Not Found') } if (urlParts.length === 2) { @@ -455,12 +455,12 @@ const handleRequest = async (request, response) => { ${projectsText}

See all!

- `) + `, user.username) } else if (compareArr(urlParts.slice(2), ['projects'])) { return page(request, response, fixWS` -

${user.username}'s projects

+

Projects by ${user.username}

${await templates.projectList(`https://api.scratch.mit.edu/users/${username}/projects`, pathname, pageNumber)} - `) + `, `Projects by ${user.username}`) } } @@ -477,13 +477,13 @@ const handleRequest = async (request, response) => { if (urlParts.length === 0) { return page(request, response, fixWS` You are at the homepage. Sorry, I haven't implmented any content for it yet. - `) + `, 'Scratch Homepage') } response.statusCode = 404 return page(request, response, fixWS` 404. Sorry, I'm not sure where you are right now. - `) + `, 'Page Not Found') } const server = http.createServer((request, response) => { @@ -492,7 +492,7 @@ const server = http.createServer((request, response) => { response.statusCode = 500 return page(request, response, fixWS` 500. Sorry, there was an internal server error. - `) + `, 'Internal Server Error') }) }) -- cgit 1.3.0-6-gf8a5