feat: auto-link phrases in the resolve answer (tracer)
- golem15_seo_autolinks (migration 202610280007) and the settings column autolink_max (Links tab, 0 to 20, default 3) - classes/autolinks.go: checked save and delete with history, ForPage - ok resolve answers carry autolinks for the page's locale without disabled phrases and links to the page itself, and autolink_max
This commit is contained in:
47
updates/202610280007_create_golem15_seo_autolinks.go
Normal file
47
updates/202610280007_create_golem15_seo_autolinks.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// createAutolinks creates golem15_seo_autolinks, the auto-link phrases
|
||||
// (D-82, P33-45): a phrase, the address it links to, its locale (empty for
|
||||
// every locale), whether it is active, where it came from (manual,
|
||||
// keyphrase or mcp) and a note, one row per phrase (any letter case) and
|
||||
// locale. The settings get autolink_max, the phrases linked in one text
|
||||
// at most (3 by default, 0 turns auto-linking off).
|
||||
var createAutolinks = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202610280007_create_golem15_seo_autolinks",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if err := tx.Exec(`CREATE TABLE golem15_seo_autolinks (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
phrase TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
locale TEXT NOT NULL DEFAULT '',
|
||||
enabled BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
origin TEXT NOT NULL DEFAULT 'manual',
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMP(0) NULL,
|
||||
updated_at TIMESTAMP(0) NULL
|
||||
)`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Exec(`CREATE UNIQUE INDEX golem15_seo_autolinks_phrase ON golem15_seo_autolinks (lower(phrase), locale)`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Exec(`ALTER TABLE golem15_seo_settings ADD COLUMN autolink_max INTEGER NOT NULL DEFAULT 3`).Error
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
if err := tx.Exec(`ALTER TABLE golem15_seo_settings DROP COLUMN IF EXISTS autolink_max`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Exec(`DROP TABLE IF EXISTS golem15_seo_autolinks`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(createAutolinks...)
|
||||
}
|
||||
Reference in New Issue
Block a user