"Today" link no longer goes directly to editor
This commit is contained in:
@@ -28,7 +28,8 @@ type diaryHandler struct{}
|
|||||||
// page anchor (or to the year-file editor when ?edit is set).
|
// page anchor (or to the year-file editor when ?edit is set).
|
||||||
//
|
//
|
||||||
// 1. `today` / `this-month` / `this-year` shortcuts resolve directly to a
|
// 1. `today` / `this-month` / `this-year` shortcuts resolve directly to a
|
||||||
// year+anchor target (or insert flow when today's section is missing).
|
// year+anchor target (never the editor, even when today's section does
|
||||||
|
// not exist yet).
|
||||||
// 2. A virtual month URL (/diary/<root>/YYYY/MM/) redirects to
|
// 2. A virtual month URL (/diary/<root>/YYYY/MM/) redirects to
|
||||||
// /diary/<root>/YYYY/#YYYY-MM (or to ?edit§ion=N when ?edit is set).
|
// /diary/<root>/YYYY/#YYYY-MM (or to ?edit§ion=N when ?edit is set).
|
||||||
// 3. A virtual day URL (/diary/<root>/YYYY/MM/DD/) redirects to
|
// 3. A virtual day URL (/diary/<root>/YYYY/MM/DD/) redirects to
|
||||||
@@ -57,7 +58,7 @@ func (d *diaryHandler) dateShortcutRedirect(root, fsPath, urlPath string) (strin
|
|||||||
|
|
||||||
parentFS := filepath.Dir(fsPath)
|
parentFS := filepath.Dir(fsPath)
|
||||||
parentURLPath := parentURL(urlPath)
|
parentURLPath := parentURL(urlPath)
|
||||||
_, diaryRootFS, diaryRootURL, ok := findDiaryContext(root, parentFS, parentURLPath)
|
_, _, diaryRootURL, ok := findDiaryContext(root, parentFS, parentURLPath)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
@@ -71,16 +72,7 @@ func (d *diaryHandler) dateShortcutRedirect(root, fsPath, urlPath string) (strin
|
|||||||
switch base {
|
switch base {
|
||||||
case "today":
|
case "today":
|
||||||
dayHeading := fmt.Sprintf("%s-%s-%s", year, month, day)
|
dayHeading := fmt.Sprintf("%s-%s-%s", year, month, day)
|
||||||
raw, _ := os.ReadFile(filepath.Join(diaryRootFS, year, "index.md"))
|
return yearURL + "#" + dayHeading, true
|
||||||
sections := splitSections(raw)
|
|
||||||
if _, found := findSectionIndex(sections, dayHeading); found {
|
|
||||||
return yearURL + "#" + dayHeading, true
|
|
||||||
}
|
|
||||||
// Missing day: route through the insert flow so today's section
|
|
||||||
// is spliced in at the right chronological position.
|
|
||||||
insertIdx := computeInsertIndex(sections, dayHeading)
|
|
||||||
return fmt.Sprintf("%s?edit&insert_before=%d&heading=%s",
|
|
||||||
yearURL, insertIdx, url.QueryEscape(dayHeading)), true
|
|
||||||
case "this-month":
|
case "this-month":
|
||||||
return yearURL + "#" + fmt.Sprintf("%s-%s", year, month), true
|
return yearURL + "#" + fmt.Sprintf("%s-%s", year, month), true
|
||||||
case "this-year":
|
case "this-year":
|
||||||
|
|||||||
Reference in New Issue
Block a user