add local TailwindCSS, fix side bar folder view, add more function to Markdown editor and allow .markdown files
This commit is contained in:
@@ -96,8 +96,8 @@ func (h *Handlers) CreateNoteHandler(c *gin.Context) {
|
||||
title += ".md"
|
||||
ext = "md"
|
||||
} else {
|
||||
// Has extension: allow if md or in allowed file extensions
|
||||
allowed := ext == "md"
|
||||
// Has extension: allow if md/markdown or in allowed file extensions
|
||||
allowed := (ext == "md" || ext == "markdown")
|
||||
if !allowed {
|
||||
for _, a := range h.config.AllowedFileExtensions {
|
||||
if strings.EqualFold(a, ext) {
|
||||
@@ -143,7 +143,7 @@ func (h *Handlers) CreateNoteHandler(c *gin.Context) {
|
||||
|
||||
// Redirect based on extension
|
||||
redirect := h.config.URLPrefix + "/note/" + notePath
|
||||
if strings.ToLower(ext) != "md" {
|
||||
if e := strings.ToLower(ext); e != "md" && e != "markdown" {
|
||||
redirect = h.config.URLPrefix + "/view_text/" + notePath
|
||||
}
|
||||
|
||||
@@ -158,11 +158,12 @@ func (h *Handlers) CreateNoteHandler(c *gin.Context) {
|
||||
func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
notePath := strings.TrimPrefix(c.Param("path"), "/")
|
||||
|
||||
if !strings.HasSuffix(notePath, ".md") {
|
||||
lp := strings.ToLower(notePath)
|
||||
if !(strings.HasSuffix(lp, ".md") || strings.HasSuffix(lp, ".markdown")) {
|
||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||
"error": "Invalid note path",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "Note path must end with .md",
|
||||
"message": "Note path must end with .md or .markdown",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
@@ -236,7 +237,13 @@ func (h *Handlers) EditNotePageHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
title := strings.TrimSuffix(filepath.Base(notePath), ".md")
|
||||
base := filepath.Base(notePath)
|
||||
var title string
|
||||
if strings.HasSuffix(strings.ToLower(base), ".markdown") {
|
||||
title = strings.TrimSuffix(base, ".markdown")
|
||||
} else {
|
||||
title = strings.TrimSuffix(base, ".md")
|
||||
}
|
||||
folderPath := filepath.Dir(notePath)
|
||||
if folderPath == "." {
|
||||
folderPath = ""
|
||||
@@ -264,7 +271,8 @@ func (h *Handlers) EditNoteHandler(c *gin.Context) {
|
||||
notePath := strings.TrimPrefix(c.Param("path"), "/")
|
||||
content := c.PostForm("content")
|
||||
|
||||
if !strings.HasSuffix(notePath, ".md") {
|
||||
lp := strings.ToLower(notePath)
|
||||
if !(strings.HasSuffix(lp, ".md") || strings.HasSuffix(lp, ".markdown")) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid note path"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1079,11 +1079,12 @@ func (h *Handlers) FolderHandler(c *gin.Context) {
|
||||
func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
notePath := strings.TrimPrefix(c.Param("path"), "/")
|
||||
|
||||
if !strings.HasSuffix(notePath, ".md") {
|
||||
// Allow both .md and .markdown files
|
||||
if !(strings.HasSuffix(strings.ToLower(notePath), ".md") || strings.HasSuffix(strings.ToLower(notePath), ".markdown")) {
|
||||
c.HTML(http.StatusBadRequest, "error", gin.H{
|
||||
"error": "Invalid note path",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "Note path must end with .md",
|
||||
"message": "Note path must end with .md or .markdown",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
@@ -1143,15 +1144,48 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
fullPath := filepath.Join(h.config.NotesDir, notePath)
|
||||
|
||||
if _, err := os.Stat(fullPath); os.IsNotExist(err) {
|
||||
c.HTML(http.StatusNotFound, "error", gin.H{
|
||||
"error": "Note not found",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "The requested note does not exist",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
// Fallback: try the alternate markdown extension
|
||||
base := filepath.Base(notePath)
|
||||
dir := filepath.Dir(notePath)
|
||||
lower := strings.ToLower(base)
|
||||
var alt string
|
||||
if strings.HasSuffix(lower, ".md") {
|
||||
alt = base[:len(base)-len(".md")] + ".markdown"
|
||||
} else if strings.HasSuffix(lower, ".markdown") {
|
||||
alt = base[:len(base)-len(".markdown")] + ".md"
|
||||
}
|
||||
if alt != "" {
|
||||
altRel := alt
|
||||
if dir != "." && dir != "" {
|
||||
altRel = filepath.Join(dir, alt)
|
||||
}
|
||||
altFull := filepath.Join(h.config.NotesDir, altRel)
|
||||
if _, err2 := os.Stat(altFull); err2 == nil {
|
||||
// Use the alternate path
|
||||
notePath = altRel
|
||||
fullPath = altFull
|
||||
} else {
|
||||
c.HTML(http.StatusNotFound, "error", gin.H{
|
||||
"error": "Note not found",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "The requested note does not exist",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.HTML(http.StatusNotFound, "error", gin.H{
|
||||
"error": "Note not found",
|
||||
"app_name": h.config.AppName,
|
||||
"message": "The requested note does not exist",
|
||||
"ContentTemplate": "error_content",
|
||||
"ScriptsTemplate": "error_scripts",
|
||||
"Page": "error",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(fullPath)
|
||||
@@ -1193,7 +1227,16 @@ func (h *Handlers) NoteHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
title := strings.TrimSuffix(filepath.Base(notePath), ".md")
|
||||
base := filepath.Base(notePath)
|
||||
lower := strings.ToLower(base)
|
||||
var title string
|
||||
if strings.HasSuffix(lower, ".markdown") {
|
||||
title = base[:len(base)-len(".markdown")]
|
||||
} else if strings.HasSuffix(lower, ".md") {
|
||||
title = base[:len(base)-len(".md")]
|
||||
} else {
|
||||
title = strings.TrimSuffix(base, filepath.Ext(base))
|
||||
}
|
||||
folderPath := filepath.Dir(notePath)
|
||||
if folderPath == "." {
|
||||
folderPath = ""
|
||||
@@ -1679,7 +1722,7 @@ func (h *Handlers) SearchHandler(c *gin.Context) {
|
||||
|
||||
// Skip disallowed files
|
||||
ext := strings.ToLower(filepath.Ext(relPath))
|
||||
isMD := ext == ".md"
|
||||
isMD := ext == ".md" || ext == ".markdown"
|
||||
if !isMD && !models.IsAllowedFile(relPath, h.config.AllowedFileExtensions) {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user