Simplify development workflow and fix content editing conflicts
- Replace complex multi-server setup (live-server + API) with unified Go server
- Serve all sites at /sites/{site_id} endpoints, eliminating port conflicts
- Fix content-type middleware to serve proper MIME types for static files
- Prevent script injection duplication with future-proof CDN-compatible detection
- Remove auto page reload from enhance button to eliminate editing interruptions
- Enable seamless content editing workflow with manual enhancement control
Development now requires only 'just dev' instead of complex demo commands.
All sites immediately available at localhost:8080 without hot reload conflicts.
This commit is contained in:
@@ -352,6 +352,11 @@ func (i *Injector) InjectDemoGateIfNeeded(doc *html.Node) {
|
||||
|
||||
// InjectEditorScript injects the insertr.js library and initialization script
|
||||
func (i *Injector) InjectEditorScript(doc *html.Node) {
|
||||
// Check if script is already injected
|
||||
if i.hasInsertrScript(doc) {
|
||||
return
|
||||
}
|
||||
|
||||
// Find the head element for the script tag
|
||||
headNode := i.findHeadElement(doc)
|
||||
if headNode == nil {
|
||||
@@ -360,8 +365,8 @@ func (i *Injector) InjectEditorScript(doc *html.Node) {
|
||||
}
|
||||
|
||||
// Create script element that loads insertr.js from our server
|
||||
scriptHTML := fmt.Sprintf(`<script src="http://localhost:8080/insertr.js"></script>
|
||||
<script type="text/javascript">
|
||||
scriptHTML := fmt.Sprintf(`<script src="http://localhost:8080/insertr.js" data-insertr-injected="true"></script>
|
||||
<script type="text/javascript" data-insertr-injected="true">
|
||||
// Initialize insertr for demo sites
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
if (typeof window.Insertr !== 'undefined') {
|
||||
@@ -461,6 +466,28 @@ func (i *Injector) hasInsertrGate(node *html.Node) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// hasInsertrScript checks if document already has insertr script injected
|
||||
// Uses data-insertr-injected attribute for reliable detection that works with:
|
||||
// - CDN URLs with version numbers (jsdelivr.net/npm/@insertr/lib@1.2.3/insertr.js)
|
||||
// - Minified versions (insertr.min.js)
|
||||
// - Query parameters (insertr.js?v=abc123)
|
||||
// - Different CDN domains (unpkg.com, cdn.example.com)
|
||||
func (i *Injector) hasInsertrScript(node *html.Node) bool {
|
||||
if node.Type == html.ElementNode && node.Data == "script" {
|
||||
for _, attr := range node.Attr {
|
||||
if attr.Key == "data-insertr-injected" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
for child := node.FirstChild; child != nil; child = child.NextSibling {
|
||||
if i.hasInsertrScript(child) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// findBodyElement finds the <body> element
|
||||
func (i *Injector) findBodyElement(node *html.Node) *html.Node {
|
||||
if node.Type == html.ElementNode && node.Data == "body" {
|
||||
|
||||
Reference in New Issue
Block a user