Skip to content

Commit 0dfde7b

Browse files
committed
add custom widget extension
1 parent 7815b96 commit 0dfde7b

File tree

4 files changed

+113
-26
lines changed

4 files changed

+113
-26
lines changed

docs/Usage.md

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,65 @@ xlog --help
33
44
Usage of xlog:
55
-activitypub.domain string
6-
domain used for activitypub stream absolute URLs
6+
domain used for activitypub stream absolute URLs
77
-activitypub.icon string
8-
the path to the activitypub profile icon. mastodon use it as profile picture for example. (default "/public/logo.png")
8+
the path to the activitypub profile icon. mastodon use it as profile picture for example. (default "/public/logo.png")
99
-activitypub.image string
10-
the path to the activitypub profile image. mastodon use it as profile cover for example. (default "/public/logo.png")
10+
the path to the activitypub profile image. mastodon use it as profile cover for example. (default "/public/logo.png")
1111
-activitypub.summary string
12-
summary of the user for activitypub actor
12+
summary of the user for activitypub actor
1313
-activitypub.username string
14-
username for activitypub actor
14+
username for activitypub actor
1515
-bind string
16-
IP and port to bind the web server to (default "127.0.0.1:3000")
16+
IP and port to bind the web server to (default "127.0.0.1:3000")
1717
-build string
18-
Build all pages as static site in this directory
18+
Build all pages as static site in this directory
19+
-custom_after_view string
20+
path to a file it's content will be included in every page AFTER the content of the page
21+
-custom_before_view string
22+
path to a file it's content will be included in every page BEFORE the content of the page
1923
-custom_css string
20-
Custom CSS file path
24+
Custom CSS file path
25+
-custom_head string
26+
path to a file it's content will be included in every page <head> tag
2127
-disqus string
22-
Disqus domain name for example: xlog-emadelsaid.disqus.com
28+
Disqus domain name for example: xlog-emadelsaid.disqus.com
2329
-github.branch string
24-
Github repository branch to use for 'edit on Github' quick action (default "master")
30+
[Deprecated] Github repository branch to use for 'edit on Github' quick action (default "master")
2531
-github.repo string
26-
Github repository to use for 'edit on Github' quick action
32+
[Deprecated] Github repository to use for 'edit on Github' quick action e.g https://github.com/emad-elsaid/xlog
33+
-github.url string
34+
Repository url for 'edit on Github' quick action e.g https://github.com/emad-elsaid/xlog/edit/master/docs
2735
-gpg string
28-
PGP key ID to decrypt and edit .md.pgp files using gpg. if empty encryption will be off
36+
PGP key ID to decrypt and edit .md.pgp files using gpg. if empty encryption will be off
2937
-html
30-
Consider HTML files as pages
38+
Consider HTML files as pages
3139
-index string
32-
Index file name used as home page (default "index")
40+
Index file name used as home page (default "index")
41+
-notfoundpage string
42+
Custom not found page (default "404")
3343
-og.domain string
34-
opengraph domain name to be used for meta tags of og:* and twitter:*
44+
opengraph domain name to be used for meta tags of og:* and twitter:*
3545
-pandoc
36-
Use pandoc to render .org, .rst, .rtf, .odt
46+
Use pandoc to render .org, .rst, .rtf, .odt
3747
-readonly
38-
Should xlog hide write operations, read-only means all write operations will be disabled
48+
Should xlog hide write operations, read-only means all write operations will be disabled
3949
-rss.description string
40-
RSS feed description
50+
RSS feed description
4151
-rss.domain string
42-
RSS domain name to be used for RSS feed. without HTTPS://
52+
RSS domain name to be used for RSS feed. without HTTPS://
4353
-rss.limit int
44-
Limit the number of items in the RSS feed to this amount (default 30)
54+
Limit the number of items in the RSS feed to this amount (default 30)
4555
-serve-insecure
46-
Accept http connections and forward crsf cookie over non secure connections
56+
Accept http connections and forward crsf cookie over non secure connections
4757
-sidebar
48-
Should render sidebar. (default true)
58+
Should render sidebar. (default true)
4959
-sitemap.domain string
50-
domain name without protocol or trailing / to use for sitemap loc
60+
domain name without protocol or trailing / to use for sitemap loc
5161
-sitename string
52-
Site name is the name that appears on the header beside the logo and in the title tag (default "XLOG")
62+
Site name is the name that appears on the header beside the logo and in the title tag (default "XLOG")
5363
-source string
54-
Directory that will act as a storage (default "/path/to/source")
64+
Directory that will act as a storage (default "/home/emad/code/xlog")
5565
-twitter.username string
56-
user twitter account @handle. including the @
66+
user twitter account @handle. including the @
5767
```

docs/official extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Defined under `/extensions` sub package. each extension is a subpackage. **All e
77
| Autolink | Shorten a link string so it wouldn't take unnecessary space |
88
| Autolink pages | Convert a page name mentions in the middle of text to a link |
99
| Custom CSS | Allow to add custom CSS file to the head of the page |
10+
| Custom Widget | Allow specifying content that is added in <head> tag, before or after the content |
1011
| Date | Detects dates and converts them to link to a page which lists all pages mentions it |
1112
| Disqus | Add Disqus comments after the view page if -disqus flag is passed |
1213
| Emoji | Emoji autocomplete while editing |

extensions/all/all.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
_ "github.com/emad-elsaid/xlog/extensions/autolink"
77
_ "github.com/emad-elsaid/xlog/extensions/autolink_pages"
88
_ "github.com/emad-elsaid/xlog/extensions/custom_css"
9+
_ "github.com/emad-elsaid/xlog/extensions/custom_widget"
910
_ "github.com/emad-elsaid/xlog/extensions/date"
1011
_ "github.com/emad-elsaid/xlog/extensions/disqus"
1112
_ "github.com/emad-elsaid/xlog/extensions/embed"

extensions/custom_widget/main.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package custom_widget
2+
3+
import (
4+
"flag"
5+
"html/template"
6+
"os"
7+
8+
. "github.com/emad-elsaid/xlog"
9+
)
10+
11+
var head_file, before_view_file, after_view_file string
12+
13+
func init() {
14+
flag.StringVar(&head_file, "custom_head", "", "path to a file it's content will be included in every page <head> tag")
15+
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")
16+
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")
17+
18+
RegisterWidget(HEAD_WIDGET, 1, custom_head)
19+
RegisterWidget(BEFORE_VIEW_WIDGET, 1, custom_before_view)
20+
RegisterWidget(AFTER_VIEW_WIDGET, 1, custom_after_view)
21+
}
22+
23+
var head_content []byte
24+
25+
func custom_head(_ Page) template.HTML {
26+
if head_file == "" {
27+
return ""
28+
}
29+
30+
if head_content == nil {
31+
var err error
32+
head_content, err = os.ReadFile(head_file)
33+
if err != nil {
34+
panic(err)
35+
}
36+
}
37+
38+
return template.HTML(head_content)
39+
}
40+
41+
var before_view_content []byte
42+
43+
func custom_before_view(_ Page) template.HTML {
44+
if before_view_file == "" {
45+
return ""
46+
}
47+
48+
if before_view_content == nil {
49+
var err error
50+
before_view_content, err = os.ReadFile(before_view_file)
51+
if err != nil {
52+
panic(err)
53+
}
54+
}
55+
56+
return template.HTML(before_view_content)
57+
}
58+
59+
var after_view_content []byte
60+
61+
func custom_after_view(_ Page) template.HTML {
62+
if after_view_file == "" {
63+
return ""
64+
}
65+
66+
if after_view_content == nil {
67+
var err error
68+
after_view_content, err = os.ReadFile(after_view_file)
69+
if err != nil {
70+
panic(err)
71+
}
72+
}
73+
74+
return template.HTML(after_view_content)
75+
}

0 commit comments

Comments
 (0)