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

Commit

Permalink
gah timezones and htaccess
Browse files Browse the repository at this point in the history
  • Loading branch information
anli5005 committed Dec 30, 2023
1 parent cd671bd commit 9057ba7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 30 deletions.
11 changes: 6 additions & 5 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Enable rewrite engine
RewriteEngine On

# Check if the .html version of the requested resource exists
RewriteCond %{REQUEST_FILENAME}.html -f
# Rewrite to .html version if existing (for requests without an extension)
RewriteRule ^([^\.]+)$ $1.html [NC,L]
# Redirect requests to .html when the .html file exists
# This works even if a directory with the same name exists
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.*?)/?$ $1.html [NC,L]

# Custom error document
ErrorDocument 404 /404.html
ErrorDocument 404 /~cis1951/404.html

# Internally rewrite requests to 404.html, while maintaining the 404 status
RewriteCond %{ENV:REDIRECT_STATUS} ^$
Expand Down
19 changes: 7 additions & 12 deletions app/assignments/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { allHomework, allAssessments } from 'contentlayer/generated'
import { Card } from '@/components/Card'
import Link from 'next/link'
import { FormattedDate, defaultTimezone } from '@/components/FormattedDate'
import { toDate } from 'date-fns-tz'
import { FormattedDate } from '@/components/FormattedDate'

type Assignment = {
title: string
Expand All @@ -17,22 +16,18 @@ type Assignment = {
sortDate: Date
}

export function parseDate(str: string) {
return toDate(str, { timeZone: defaultTimezone })
}

export const formattedHomework: Assignment[] = allHomework.map(hw => {
const due = parseDate(hw.dueDate)
const due = new Date(hw.dueDate)

return {
title: hw.title,
href: `/assignments/hw/${hw.slug}`,
isReleased: hw.isReleased,
releaseDate: hw.releaseDate && parseDate(hw.releaseDate),
releaseDate: hw.releaseDate && new Date(hw.releaseDate),
dates: [
...(hw.auxiliaryDates ?? []).map(aux => ({
name: aux.name,
date: parseDate(aux.date),
date: new Date(aux.date),
specifyTime: true,
})),
{
Expand All @@ -41,18 +36,18 @@ export const formattedHomework: Assignment[] = allHomework.map(hw => {
specifyTime: true,
}
],
sortDate: parseDate(hw.dueDate),
sortDate: new Date(hw.dueDate),
}
})

export const formattedAssessments = allAssessments.map(a => {
const date = parseDate(a.assessmentDate)
const date = new Date(a.assessmentDate)

return {
title: a.title,
href: `/assignments/assessment/${a.slug}`,
isReleased: a.isReleased,
releaseDate: a.releaseDate && parseDate(a.releaseDate),
releaseDate: a.releaseDate && new Date(a.releaseDate),
dates: [
{
name: "Scheduled",
Expand Down
12 changes: 3 additions & 9 deletions app/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ export type MenuItemActivatorProps = {

export function MenuItemActivator({ item }: MenuItemActivatorProps) {
const context = useMenuContext()
const pathname = usePathname()
useEffect(() => {
context.setActiveItem(item)
}, [])
}, [pathname])

return null
}
Expand All @@ -100,14 +101,7 @@ function MenuItem({ id, title, icon, href }: MenuItemProps) {
let containerClassName = "flex gap-3 transition-[margin-left] justify-center text-center md:text-left"
if (!isActive) containerClassName += " md:group-hover:ml-1"

return <Link className={className} href={href} onClick={e => {
if (href === "/") {
// HACK: For some reason navigating to / forces a full refresh
// So we just intercept it and do it ourselves instead
router.push("/")
e.preventDefault()
}
}}>
return <Link className={className} href={href}>
<div className={containerClassName}>
<div className="w-4">{icon}</div>
<div className="md:grow line-clamp-1 overflow-hidden overflow-ellipsis">{title}</div>
Expand Down
2 changes: 1 addition & 1 deletion components/UpcomingAssignments.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { formattedAssessments, formattedHomework, AssignmentTable } from "@/app/assignments/page"

const threshold = 5 * 7 * 24 * 60 * 60 * 1000 // 3 weeks
const threshold = 3 * 7 * 24 * 60 * 60 * 1000 // 3 weeks
const thresholdText = "3 weeks"

const upcoming = [...formattedHomework, ...formattedAssessments].filter(({ sortDate }) => {
Expand Down
2 changes: 1 addition & 1 deletion content/homework/hw0.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: HW0 - Xcode Setup
isReleased: true
dueDate: 2024-01-22T23:59:00
dueDate: 2024-01-22T23:59:00-05:00
---

Just send us a screenshot of Xcode working
4 changes: 2 additions & 2 deletions content/homework/hw1.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: HW1 - Basic Swift
isReleased: false
dueDate: 2024-01-23T23:59:00
releaseDate: 2024-01-24T23:59:00
dueDate: 2024-01-23T23:59:00-05:00
releaseDate: 2024-01-24T23:59:00-05:00
---
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const nextConfig = {
basePath: "/~cis1951",
output: "export",
pageExtensions: ["js", "jsx", "ts", "tsx", "mdx"],
trailingSlash: true,
}

module.exports = withContentlayer(nextConfig)

0 comments on commit 9057ba7

Please sign in to comment.