aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2024-05-24 16:13:34 -0400
committerXe Iaso <me@xeiaso.net>2024-05-24 16:13:34 -0400
commit21d75e1fc5be9b06029543304cc2e49ff8b58607 (patch)
tree3f9e18809d82e83df512904d1c15578dea9c037d
parentd69787e5c65378a54de622fafbcce2a08a5c21f5 (diff)
downloadxesite-21d75e1fc5be9b06029543304cc2e49ff8b58607.tar.xz
xesite-21d75e1fc5be9b06029543304cc2e49ff8b58607.zip
lume: add events page fed by Events API
Signed-off-by: Xe Iaso <me@xeiaso.net>
-rw-r--r--cmd/xesite/main.go22
-rw-r--r--internal/lume/lume.go40
-rw-r--r--lume/src/_components/EventCard.jsx34
-rw-r--r--lume/src/_data/.gitignore1
-rw-r--r--lume/src/events.jsx31
5 files changed, 102 insertions, 26 deletions
diff --git a/cmd/xesite/main.go b/cmd/xesite/main.go
index fd30211..b4b238c 100644
--- a/cmd/xesite/main.go
+++ b/cmd/xesite/main.go
@@ -27,7 +27,7 @@ var (
gitRepo = flag.String("git-repo", "https://github.com/Xe/site", "Git repository to clone")
githubSecret = flag.String("github-secret", "", "GitHub secret to use for webhooks")
internalAPIBind = flag.String("internal-api-bind", ":3001", "Port to listen on for the internal API")
- mimiAnnounceURL = flag.String("mimi-announce-url", "", "URL to use for the mimi announce service")
+ miURL = flag.String("mimi-announce-url", "", "Mi url (named mimi-announce-url for historical reasons)")
patreonSaasProxyURL = flag.String("patreon-saasproxy-url", "http://xesite-patreon-saasproxy.flycast", "URL to use for the patreon saasproxy")
siteURL = flag.String("site-url", "https://xeiaso.net/", "URL to use for the site")
)
@@ -44,10 +44,6 @@ func main() {
log.Fatal(err)
}
- flag.VisitAll(func(f *flag.Flag) {
- slog.Debug("flag", "name", f.Name, "value", f.Value)
- })
-
os.MkdirAll(*dataDir, 0700)
os.MkdirAll(filepath.Join(*dataDir, "tsnet"), 0700)
@@ -57,14 +53,14 @@ func main() {
}
fs, err := lume.New(ctx, &lume.Options{
- Branch: *gitBranch,
- Repo: *gitRepo,
- StaticSiteDir: "lume",
- URL: *siteURL,
- Development: *devel,
- PatreonClient: pc,
- DataDir: *dataDir,
- MimiAnnounceURL: *mimiAnnounceURL,
+ Branch: *gitBranch,
+ Repo: *gitRepo,
+ StaticSiteDir: "lume",
+ URL: *siteURL,
+ Development: *devel,
+ PatreonClient: pc,
+ DataDir: *dataDir,
+ MiURL: *miURL,
})
if err != nil {
log.Fatal(err)
diff --git a/internal/lume/lume.go b/internal/lume/lume.go
index 2dc5b74..06bd79d 100644
--- a/internal/lume/lume.go
+++ b/internal/lume/lume.go
@@ -21,11 +21,13 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/twitchtv/twirp"
+ "google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
"gopkg.in/mxpv/patreon-go.v1"
"tailscale.com/metrics"
"xeiaso.net/v4/internal/config"
"xeiaso.net/v4/internal/jsonfeed"
+ "xeiaso.net/v4/pb/external/mi"
"xeiaso.net/v4/pb/external/mimi/announce"
"xeiaso.net/v4/pb/external/protofeed"
)
@@ -70,7 +72,9 @@ type FS struct {
opt *Options
conf *config.Config
- mimiClient announce.Announce
+ // assumption: announce and events are on the same server
+ mimiClient announce.Announce
+ eventsClient mi.Events
fs fs.FS
lock sync.Mutex
@@ -122,14 +126,14 @@ func (f *FS) Open(name string) (fs.File, error) {
}
type Options struct {
- Development bool
- Branch string
- Repo string
- StaticSiteDir string
- URL string
- PatreonClient *patreon.Client
- DataDir string
- MimiAnnounceURL string
+ Development bool
+ Branch string
+ Repo string
+ StaticSiteDir string
+ URL string
+ PatreonClient *patreon.Client
+ DataDir string
+ MiURL string
}
func New(ctx context.Context, o *Options) (*FS, error) {
@@ -206,10 +210,10 @@ func New(ctx context.Context, o *Options) (*FS, error) {
siteCommit = ref.Hash().String()
}
- if o.MimiAnnounceURL != "" {
- mimiClient := announce.NewAnnounceProtobufClient(o.MimiAnnounceURL, &http.Client{})
- fs.mimiClient = mimiClient
- slog.Debug("mimi integration enabled")
+ if o.MiURL != "" {
+ fs.mimiClient = announce.NewAnnounceProtobufClient(o.MiURL, &http.Client{})
+ fs.eventsClient = mi.NewEventsProtobufClient(o.MiURL, &http.Client{})
+ slog.Debug("mi integration enabled")
}
conf, err := config.Load(filepath.Join(fs.repoDir, "config.dhall"))
@@ -379,6 +383,15 @@ func (f *FS) writeConfig(siteCommit string) error {
}
}
+ var events *mi.EventFeed
+ if f.eventsClient != nil {
+ var err error
+ events, err = f.eventsClient.Get(context.Background(), &emptypb.Empty{})
+ if err != nil {
+ slog.Error("failed to fetch events", "err", err)
+ }
+ }
+
if err := os.MkdirAll(dataDir, 0o755); err != nil {
return err
}
@@ -389,6 +402,7 @@ func (f *FS) writeConfig(siteCommit string) error {
"characters.json": f.conf.Characters,
"commit.json": map[string]any{"hash": siteCommit},
"contactLinks.json": f.conf.ContactLinks,
+ "events.json": events,
"jobHistory.json": f.conf.JobHistory,
"notableProjects.json": f.conf.NotableProjects,
"pronouns.json": f.conf.Pronouns,
diff --git a/lume/src/_components/EventCard.jsx b/lume/src/_components/EventCard.jsx
new file mode 100644
index 0000000..62dbcfe
--- /dev/null
+++ b/lume/src/_components/EventCard.jsx
@@ -0,0 +1,34 @@
+const timestampPBtoDate = ({ seconds }) => {
+ return new Date(seconds * 1000);
+};
+
+const formatDate = (date) => {
+ return date.toLocaleDateString('en-US', {
+ month: 'long',
+ day: 'numeric',
+ year: 'numeric',
+ });
+};
+
+// takes within.website.x.mi.Event
+export default ({ name, url, start_date, end_date, location, description }) => {
+ const startDate = formatDate(timestampPBtoDate(start_date));
+ const endDate = formatDate(timestampPBtoDate(end_date));
+ return (
+ <div className="rounded-lg p-4 bg-bg-1 dark:bg-bgDark-1">
+ <h2 className="text-lg mb-2 text-fg-1 dark:text-fgDark-1">
+ <a href={url} target="_blank" rel="noopener noreferrer" className="text-blue-dark dark:text-blueDark-light">
+ {name} <span role="img" aria-label="link">🔗</span>
+ </a>
+ </h2>
+ <div className="card-content text-fg-1 dark:text-fgDark-1">
+ <p>
+ {location} - {startDate} {start_date.seconds !== end_date.seconds ? `thru ${endDate})}` : ""}
+ </p>
+ <p className="prose">
+ {description}
+ </p>
+ </div>
+ </div>
+ );
+}; \ No newline at end of file
diff --git a/lume/src/_data/.gitignore b/lume/src/_data/.gitignore
index 2d0f2ed..0f87891 100644
--- a/lume/src/_data/.gitignore
+++ b/lume/src/_data/.gitignore
@@ -3,6 +3,7 @@ authors.json
characters.json
commit.json
contactLinks.json
+events.json
jobHistory.json
notableProjects.json
pronouns.json
diff --git a/lume/src/events.jsx b/lume/src/events.jsx
new file mode 100644
index 0000000..4a313b2
--- /dev/null
+++ b/lume/src/events.jsx
@@ -0,0 +1,31 @@
+import EventCard from "./_components/EventCard.jsx";
+
+export const title = "Events";
+export const layout = "base.njk";
+export const date = "2012-12-31";
+export const desc = "A list of the upcoming events that I plan to attend and what I'll do there.";
+
+export default ({ events }) => {
+ if (events.events === undefined) {
+ return (
+ <>
+ <h1 className="text-3xl mb-4">Events</h1>
+ <p>
+ I don't have any events planned right now or my events API is down. Check back later!
+ </p>
+ </>
+ );
+ }
+
+ return (
+ <>
+ <h1 className="text-3xl mb-4">Events</h1>
+
+ <p className="my-4">Where in the world is Xe Iaso?</p>
+
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
+ {events.events.map((event) => EventCard(event))}
+ </div>
+ </>
+ );
+} \ No newline at end of file