Remove punctuation from blog IDs
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -220,7 +219,7 @@ func editorPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if newBlog.ID == "" {
|
if newBlog.ID == "" {
|
||||||
newBlog.ID = strings.TrimSpace(strings.ToLower(strings.ReplaceAll(newBlog.Title, " ", "-")))
|
newBlog.ID = newBlog.IDFromTitle()
|
||||||
if blogApp.Contains(r.Context(), newBlog.ID) {
|
if blogApp.Contains(r.Context(), newBlog.ID) {
|
||||||
sendContent(w, r, "<p>Title is not unique!</p>", "", "")
|
sendContent(w, r, "<p>Title is not unique!</p>", "", "")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||||
@@ -59,6 +61,11 @@ func (b *Blog) HTMX(blogApp *BlogApp, ctx context.Context) string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b Blog) IDFromTitle() string {
|
||||||
|
id := strings.Join(regexp.MustCompile("([A-z]| |[0-9])*").FindAllString(b.Title, -1), "")
|
||||||
|
return strings.ReplaceAll(id, " ", "-")
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BlogApp) ConvertBlog(blog *Blog) {
|
func (b *BlogApp) ConvertBlog(blog *Blog) {
|
||||||
if !blog.StaticPage {
|
if !blog.StaticPage {
|
||||||
blog.HTMLBlog = b.conv.HTMLConvert(blog.RawBlog)
|
blog.HTMLBlog = b.conv.HTMLConvert(blog.RawBlog)
|
||||||
|
|||||||
Reference in New Issue
Block a user