From 4c32b5f4f60699077090104233143b4fa4e345f5 Mon Sep 17 00:00:00 2001 From: Raymond Wang Date: Mon, 24 Oct 2022 17:39:31 -0700 Subject: [PATCH] fix image, add g-analytics, fix component binding --- src/public/Config.ts | 2 +- src/public/components/TopBar.tsx | 5 ++-- src/util/index.ts | 21 ++++++++++---- src/{public => util}/template.html | 45 ++++++++++++++++++------------ 4 files changed, 46 insertions(+), 27 deletions(-) rename src/{public => util}/template.html (64%) diff --git a/src/public/Config.ts b/src/public/Config.ts index f23ef96..ad0838d 100644 --- a/src/public/Config.ts +++ b/src/public/Config.ts @@ -221,7 +221,7 @@ export const OFFICERS = [ { name: "Raymond Wang", position: "Webmaster", - photo: "img/officers/raymond.png", + photo: "img/officers/raymond.jpg", email: "raymond@ucsd.edu", }, { diff --git a/src/public/components/TopBar.tsx b/src/public/components/TopBar.tsx index 08e9c1e..feb019c 100644 --- a/src/public/components/TopBar.tsx +++ b/src/public/components/TopBar.tsx @@ -1,5 +1,4 @@ import * as React from "react"; -import { Component } from "react"; interface TopBarProps { links: { @@ -12,7 +11,7 @@ interface TopBarState { menuVisible: boolean; } -export default class TopBar extends Component { +export default class TopBar extends React.Component { private static HAMBURGER_POINT = 1290; constructor(props: TopBarProps) { super(props); @@ -20,7 +19,7 @@ export default class TopBar extends Component { showBurger: this.shouldShowBurger(), menuVisible: false, }; - this.toggleMenu.bind(this); + this.toggleMenu = this.toggleMenu.bind(this); window.addEventListener("resize", this.checkResize.bind(this)); } diff --git a/src/util/index.ts b/src/util/index.ts index d0b95c5..2a0a903 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -15,8 +15,15 @@ interface Website { const APP = express(); const TEMPLATE = fs - .readFileSync(path.join(__dirname, "public/template.html")) + .readFileSync(path.join(__dirname, "template.html")) .toString(); + +const GOOGLE_ANALYTICS_ID = process.env.GOOGLE_ANALYTICS_ID; + +if (!GOOGLE_ANALYTICS_ID && process.env.NODE_ENV == "production") { + throw new Error("GOOGLE_ANALYTICS_ID environment variable not defined"); +} + const WEBSITES = [ { sitename: "index", @@ -49,13 +56,13 @@ const WEBSITES = [ jsfile: "js/committees.js", cssfile: "css/styles.css", themecolor: "", - } + }, ] as Website[]; -const PORT = 9000; +const PORT = process.env.PORT ?? 9000; // Make the public directory traversible to people online -APP.use(express.static(path.join(__dirname, "public"))); +APP.use(express.static(path.join(__dirname, "../public"))); // Put the cookies as a variable in the request APP.use((req: Request, res: Response, next: NextFunction) => { req.cookies = req.headers.cookie; @@ -99,6 +106,10 @@ function generatePage(name: string): string { for (key of Object.keys(site)) { html = html.replace(new RegExp("\\$" + key.toUpperCase()), site[key]); } + html = html.replace( + new RegExp("$GOOGLE_ANALYTICS_ID", "gm"), + GOOGLE_ANALYTICS_ID + ); return html; } @@ -107,7 +118,7 @@ function generateFilePages() { for (site of WEBSITES) { const html = generatePage(site.sitename); fs.writeFileSync( - path.join(__dirname, "public/", `${site.sitename}.html`), + path.join(__dirname, "../public/", `${site.sitename}.html`), html ); } diff --git a/src/public/template.html b/src/util/template.html similarity index 64% rename from src/public/template.html rename to src/util/template.html index 5df27e1..a0b0850 100644 --- a/src/public/template.html +++ b/src/util/template.html @@ -1,19 +1,28 @@ - - - - - $TITLE - - - - - - - - - -
- - - + + + + + $TITLE + + + + + + + + + + + + +
+ + + \ No newline at end of file