« get me outta code hell

Specify page titles - scratchrlol - Simple HTML-based Scratch client
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-11-14 23:03:40 -0400
committerFlorrie <towerofnix@gmail.com>2018-11-14 23:03:40 -0400
commitd8c9bde1a563f3cae8ee93cfa0174d621109a7a6 (patch)
treea627d037f20a28f14790a89f8a718d7a9ad5b39c
parentffd70884e61f5baa52fc2b84dfcc812ea66cf783 (diff)
Specify page titles
-rwxr-xr-xindex.js38
1 files 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) => {
     <html>
       <head>
         <meta charset="utf-8">
-        <title>Scratch</title>
+        <title>${filterHTML(title)}</title>
         <link rel="stylesheet" href="/style.css">
       </head>
       <body>
@@ -264,7 +264,7 @@ const handleRequest = async (request, response) => {
           <p><label>CSRF Token: <input type="password" name="csrftoken"></label></p>
           <p><button>Login</button></p>
         </form>
-      `)
+      `, '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`
         <p>Okay, you're logged in.</p>
-      `)
+      `, 'Logged In')
     }
   }
 
@@ -291,7 +291,7 @@ const handleRequest = async (request, response) => {
           <p>Are you sure you want to log out?</p>
           <p><button>Log out</button></p>
         </form>
-      `)
+      `, '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`
         <p>Okay, you've been logged out.</p>
-      `)
+      `, 'Logged Out')
     }
   }
 
@@ -310,7 +310,7 @@ const handleRequest = async (request, response) => {
     if (!cookie.username) {
       return page(request, response, fixWS`
         <p>Sorry, you can't view your notifications until you've <a href="/login">logged in</a>.</p>
-      `)
+      `, 'Notifications')
     }
 
     const notifications = await getNotifications(cookie.username, cookie.token, pageNumber)
@@ -345,7 +345,7 @@ const handleRequest = async (request, response) => {
       <p>You are on page ${pageNumber}.
         ${notifications.length === limit && `<a href="/notifications?page=${pageNumber + 1}">Next</a>`}
         ${pageNumber > 1 && `<a href="/notifications?page=${pageNumber - 1}">Previous</a>`}</p>
-    `)
+    `, '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`
-        <h1>${project.title}</h1>
+        <h1>${filterHTML(project.title)}</h1>
         <p>Created by ${templates.user(project.author.username)}.${parentProjectText}</p>
         <p><img src="${project.image}" alt="The thumbnail for this project"></p>
         ${project.instructions ? fixWS`
@@ -412,12 +412,12 @@ const handleRequest = async (request, response) => {
           </ul>
           <p><a href="/projects/${project.id}/remixes">See all!</a></p>
         ` : ''}
-      `)
+      `, project.title)
     } else if (compareArr(urlParts.slice(2), ['remixes'])) {
       return page(request, response, fixWS`
         <h1>Remixes of ${filterHTML(project.title)}</h1>
         ${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}
         </ul>
         <p><a href="/users/${username}/projects">See all!</a></p>
-      `)
+      `, user.username)
     } else if (compareArr(urlParts.slice(2), ['projects'])) {
       return page(request, response, fixWS`
-        <h1>${user.username}'s projects</h1>
+        <h1>Projects by ${user.username}</h1>
         ${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')
   })
 })