Skip to content

Commit

Permalink
beauty update
Browse files Browse the repository at this point in the history
  • Loading branch information
loan-mgt committed Sep 5, 2024
1 parent d063278 commit b7787b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
func main() {
r := mux.NewRouter()

// Handle the calendar.ics route
r.HandleFunc("/3irc.ics", generateICSHandler).Methods("GET")
// Handle the calendar.ics route with default filename "calendar.ics"
r.HandleFunc("/3irc.ics", generate3IRCHandler).Methods("GET")

// Serve static files
r.PathPrefix("/").Handler(http.FileServer(http.Dir("static/")))
Expand All @@ -22,7 +22,8 @@ func main() {
log.Fatal(http.ListenAndServe(":8080", r))
}

func generateICSHandler(w http.ResponseWriter, r *http.Request) {
// generateICSHandler generates the ICS file and sends it in the response with a given filename
func generateICSHandler(w http.ResponseWriter, _ *http.Request, filename string) {
// Set start and end times (these could be retrieved from request parameters if needed)
start := "1725228000000" // Example start timestamp
end := "1728684000000" // Example end timestamp
Expand All @@ -48,7 +49,16 @@ func generateICSHandler(w http.ResponseWriter, r *http.Request) {
// Step 3: Generate the iCal file
icsContent := ical.GenerateICS(events)

// Step 4: Write the iCal file to the response
// Step 4: Set headers for the iCal file response with the provided filename
w.Header().Set("Content-Type", "text/calendar")
w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")

// Step 5: Write the iCal content to the response
w.Write([]byte(icsContent))
}

// generate3IRCHandler is a wrapper around generateICSHandler that uses a specific filename
func generate3IRCHandler(w http.ResponseWriter, r *http.Request) {
// Call generateICSHandler with the specific filename
generateICSHandler(w, r, "3irc_calendar.ics")
}
File renamed without changes
12 changes: 12 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CPE Calendar</title>

<meta name="description" content="Sync your CPE calendar with your personal one">
<meta name="keywords" content="calendar, ics, CPE, apple, google">
<meta name="author" content="https://github.com/loan-mgt">
<meta property="og:title" content="CPE Calendar">
<meta property="og:description" content="Sync your CPE calendar with your personal one">
<meta property="og:image" content="/static/banner.png">
<meta property="og:url" content="https://cpe-cal.for-loop.fr">
<meta property="og:type" content="website">


<link rel="icon" href="/static/favicon.svg" type="image/svg+xml">

<style>
/* CSS Variables for colors and other reusable values */
:root {
Expand Down

0 comments on commit b7787b1

Please sign in to comment.