package main import ( "encoding/json" "html" "net/http" "regexp" "strings" "time" ) func DailyPage(w http.ResponseWriter, r *http.Request) { cfg := LoadConfig() today := time.Now().Format("2006-01-02") lastProject := html.EscapeString(cfg.DailyUpdate.LastProject) body := `

Daily Update

Submit copies the formatted text to your clipboard.
` w.Header().Set("Content-Type", "text/html; charset=utf-8") _, _ = w.Write([]byte(Page("/daily", "Daily Update", body))) } type dailySubmitReq struct { Date string `json:"date"` Status string `json:"status"` Project string `json:"project"` Remarks string `json:"remarks"` } func DailySubmit(w http.ResponseWriter, r *http.Request) { var req dailySubmitReq if err := json.NewDecoder(r.Body).Decode(&req); err != nil { writeJSON(w, map[string]any{"ok": false, "error": err.Error()}) return } text := formatDailyMessage(req) if err := CopyToClipboard(text); err != nil { writeJSON(w, map[string]any{"ok": false, "error": err.Error()}) return } cfg := LoadConfig() cfg.DailyUpdate.LastProject = req.Project _ = SaveConfig(cfg) writeJSON(w, map[string]any{"ok": true, "text": text}) } func formatDailyMessage(p dailySubmitReq) string { bullets := []string{} for _, line := range strings.Split(p.Remarks, "\n") { t := strings.TrimRight(line, "\r") t = regexp.MustCompile(`^\s*[-*]\s*`).ReplaceAllString(t, "") t = strings.TrimSpace(t) if t != "" { bullets = append(bullets, "- "+t) } } lines := []string{ "Date: " + formatDailyDate(p.Date), "Status: " + p.Status, "Project: " + p.Project, "Remarks:", strings.Join(bullets, "\n"), } if p.Status == "For OT" { lines = append(lines, "@Joyce Lanot , @Reland Pigte, @Anthony Castor, @Angela Grace") } return strings.Join(lines, "\n") } func formatDailyDate(iso string) string { t, err := time.Parse("2006-01-02", iso) if err != nil { return iso } return t.Format("01/02/2006") } func writeJSON(w http.ResponseWriter, v any) { w.Header().Set("Content-Type", "application/json") _ = json.NewEncoder(w).Encode(v) }