add favicon and breadcumbs
This commit is contained in:
@ -14,11 +14,6 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
pathParamLearningType = "learning_type"
|
||||
pathParamThematicType = "thematic_type"
|
||||
)
|
||||
|
||||
func makePathTemplate(params ...string) string {
|
||||
var sb strings.Builder
|
||||
for _, param := range params {
|
||||
@ -41,9 +36,9 @@ func setupHTTP(cfg config.HTTP, srv xhttp.Server, log *slog.Logger) *http.Server
|
||||
router.HandleFunc("/updatedesc", coursesAPI.UdpateDescription).Methods(http.MethodPost)
|
||||
coursesRouter := router.PathPrefix("/courses").Subrouter()
|
||||
coursesRouter.HandleFunc("/", coursesAPI.List).Methods(http.MethodGet)
|
||||
coursesListLearningOnlyPath := makePathTemplate(pathParamLearningType)
|
||||
coursesListLearningOnlyPath := makePathTemplate(xhttp.LearningTypePathParam)
|
||||
coursesRouter.HandleFunc(coursesListLearningOnlyPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
coursesListFullPath := makePathTemplate(pathParamLearningType, pathParamThematicType)
|
||||
coursesListFullPath := makePathTemplate(xhttp.LearningTypePathParam, xhttp.ThematicTypePathParam)
|
||||
coursesRouter.HandleFunc(coursesListFullPath, coursesAPI.List).Methods(http.MethodGet)
|
||||
|
||||
courseRouter := router.PathPrefix("/course").PathPrefix("/{course_id}").Subrouter()
|
||||
@ -56,9 +51,29 @@ func setupHTTP(cfg config.HTTP, srv xhttp.Server, log *slog.Logger) *http.Server
|
||||
fs := http.FileServer(http.Dir("./assets/kurious/static/"))
|
||||
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs)).Methods(http.MethodGet)
|
||||
|
||||
router.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "./assets/kurious/robots.txt")
|
||||
}).Methods(http.MethodGet)
|
||||
registerFile := func(filepath string) {
|
||||
if !strings.HasPrefix(filepath, "/") {
|
||||
filepath = "/" + filepath
|
||||
}
|
||||
|
||||
relativePath := "./assets/kurious" + filepath
|
||||
router.HandleFunc(filepath, func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, relativePath)
|
||||
}).Methods(http.MethodGet)
|
||||
}
|
||||
|
||||
for _, file := range []string{
|
||||
"robots.txt",
|
||||
"android-chrome-192x192.png",
|
||||
"android-chrome-512x512.png",
|
||||
"apple-touch-icon.png",
|
||||
"favicon-16x16.png",
|
||||
"favicon-32x32.png",
|
||||
"favicon.ico",
|
||||
"site.webmanifest",
|
||||
} {
|
||||
registerFile(file)
|
||||
}
|
||||
} else {
|
||||
fs := kurious.AsHTTPFileHandler()
|
||||
router.PathPrefix("/").Handler(fs).Methods(http.MethodGet)
|
||||
|
||||
Reference in New Issue
Block a user