Skip to content

Commit 34aead0

Browse files
committed
register extension is global
1 parent a4aec05 commit 34aead0

File tree

38 files changed

+46
-78
lines changed

38 files changed

+46
-78
lines changed

app.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type App struct {
2828
staticDirs []fs.FS
2929

3030
// Extensions and plugins
31-
extensions []Extension
3231

3332
// Widgets
3433
widgets map[WidgetSpace]*priorityList[WidgetFunc]

extensions.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ type Extension interface {
1212
Init(*App)
1313
}
1414

15+
// Global variable to store all registered extensions
16+
var globalExtensions []Extension
17+
1518
// RegisterExtension registers a new extension
16-
func (app *App) RegisterExtension(e Extension) {
17-
app.extensions = append(app.extensions, e)
19+
func RegisterExtension(e Extension) {
20+
globalExtensions = append(globalExtensions, e)
1821
}
1922

2023
// initExtensions initializes all registered extensions
@@ -27,14 +30,14 @@ func (app *App) initExtensions() {
2730
disabled := strings.Split(app.config.DisabledExtensions, ",")
2831
disabledNames := []string{} // because the user can input wrong extension name
2932
enabledNames := []string{}
30-
for i := range app.extensions {
31-
if slices.Contains(disabled, app.extensions[i].Name()) {
32-
disabledNames = append(disabledNames, app.extensions[i].Name())
33+
for i := range globalExtensions {
34+
if slices.Contains(disabled, globalExtensions[i].Name()) {
35+
disabledNames = append(disabledNames, globalExtensions[i].Name())
3336
continue
3437
}
3538

36-
app.extensions[i].Init(app)
37-
enabledNames = append(enabledNames, app.extensions[i].Name())
39+
globalExtensions[i].Init(app)
40+
enabledNames = append(enabledNames, globalExtensions[i].Name())
3841
}
3942

4043
slog.Info("extensions", "enabled", enabledNames, "disabled", disabled)

extensions/activitypub/activitypub.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ func init() {
2727
flag.StringVar(&icon, "activitypub.icon", "/public/logo.png", "the path to the activitypub profile icon. mastodon use it as profile picture for example.")
2828
flag.StringVar(&image, "activitypub.image", "/public/logo.png", "the path to the activitypub profile image. mastodon use it as profile cover for example.")
2929

30-
app := GetApp()
31-
app.RegisterExtension(ActivityPub{})
30+
RegisterExtension(ActivityPub{})
3231
}
3332

3433
type ActivityPub struct{}

extensions/autolink/autolink.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import (
1010
)
1111

1212
func init() {
13-
app := GetApp()
14-
app.RegisterExtension(AutoLink{})
13+
RegisterExtension(AutoLink{})
1514
}
1615

1716
type AutoLink struct{}

extensions/autolink_pages/extension.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
)
99

1010
func init() {
11-
app := GetApp()
12-
app.RegisterExtension(AutoLinkPages{})
11+
RegisterExtension(AutoLinkPages{})
1312
}
1413

1514
type AutoLinkPages struct{}

extensions/blocks/blocks.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ var templates embed.FS
1818
var public embed.FS
1919

2020
func init() {
21-
app := xlog.GetApp()
22-
app.RegisterExtension(Blocks{})
21+
xlog.RegisterExtension(Blocks{})
2322
}
2423

2524
type Blocks struct{}

extensions/custom_widget/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ func init() {
1616
flag.StringVar(&before_view_file, "custom.before_view", "", "path to a file it's content will be included in every page BEFORE the content of the page")
1717
flag.StringVar(&after_view_file, "custom.after_view", "", "path to a file it's content will be included in every page AFTER the content of the page")
1818

19-
app := GetApp()
20-
app.RegisterExtension(CustomWidget{})
19+
RegisterExtension(CustomWidget{})
2120
}
2221

2322
type CustomWidget struct{}

extensions/date/extension.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
)
99

1010
func init() {
11-
app := GetApp()
12-
app.RegisterExtension(Date{})
11+
RegisterExtension(Date{})
1312
}
1413

1514
type Date struct{}

extensions/disqus/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ var domain string
3131

3232
func init() {
3333
flag.StringVar(&domain, "disqus", "", "Disqus domain name for example: xlog-emadelsaid.disqus.com")
34-
app := GetApp()
35-
app.RegisterExtension(Disqus{})
34+
RegisterExtension(Disqus{})
3635
}
3736

3837
type Disqus struct{}

extensions/editor/extension.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func init() {
2121

2222
app := xlog.GetApp()
2323
app.RequireHTMX()
24-
app.RegisterExtension(Editor{})
24+
xlog.RegisterExtension(Editor{})
2525
}
2626

2727
type Editor struct{}

0 commit comments

Comments
 (0)