511 B
page.go
package render

import (
	"strings"

	"github.com/readysite/readysite/website/models"
)

// FindByPath finds a page by its full URL path.
func FindByPath(path string) *models.Page {
	parts := strings.Split(path, "/")
	if len(parts) == 0 {
		return nil
	}

	// Try to find the page by the last segment of the path
	lastPart := parts[len(parts)-1]
	page, err := models.Pages.Get(lastPart)
	if err != nil {
		return nil
	}

	// Verify the path matches
	if page.Path() == "/"+path {
		return page
	}

	return nil
}
← Back