Skip to content

Commit

Permalink
fixed the remaing tests
Browse files Browse the repository at this point in the history
* Added the default 500 error when the HTML generator functions error
* Fixed some bugs with the string partitioning algorithm
  • Loading branch information
matheusgomes28 committed Apr 29, 2024
1 parent 74a3c69 commit f61d4f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions admin-app/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func deletePostHandler(database database.Database) func(*gin.Context) {
// removing the given ranges
func partitionString(text string, indexes [][]int) []string {

if len(text) == 0 {
return []string{}
}

partitions := make([]string, 0)
start := 0
for _, window := range indexes {
Expand Down Expand Up @@ -187,10 +191,15 @@ func transformContent(content string, shortcode_handlers map[string]*lua.LState)
regex, _ := regexp.Compile(`{{[\w.-]+(:[\w.-]+)+}}`)

shortcodes := regex.FindAllStringIndex(content, -1)
if len(shortcodes) == 0 {
return content, nil
}

partitions := partitionString(content, shortcodes)

builder := strings.Builder{}
i := 0

for i, shortcode := range shortcodes {
builder.WriteString(partitions[i])

Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func addCachableHandler(e *gin.Engine, method string, endpoint string, generator
if err != nil {
log.Error().Msgf("could not generate html: %v", err)
// TODO : Need a proper error page
// c.JSON(http.StatusInternalServerError, common.ErrorRes("could not render HTML", err))
c.JSON(http.StatusInternalServerError, common.ErrorRes("could not render HTML", err))
return
}

Expand Down

0 comments on commit f61d4f8

Please sign in to comment.