Skip to content

Commit 0b1d6fa

Browse files
committed
feat: configurable home blocks
1 parent 442cc2c commit 0b1d6fa

File tree

7 files changed

+155
-26
lines changed

7 files changed

+155
-26
lines changed

cmd/web.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,45 @@ func (s *WebServer) handleHome(w http.ResponseWriter, r *http.Request) {
245245
}
246246
}
247247

248+
// Fetch latest blocks from configured datasources for home page
249+
var homeBlocks []types.WebBlock
250+
if s.config.Home != nil && s.config.Home.Datasources != "" {
251+
// Parse comma-separated datasource names
252+
dsNames := strings.Split(s.config.Home.Datasources, ",")
253+
for _, dsName := range dsNames {
254+
dsName = strings.TrimSpace(dsName)
255+
if dsName == "" {
256+
continue
257+
}
258+
259+
// Get the latest block from this datasource (empty query, limit 1)
260+
params := storage.SearchParams{
261+
Query: "",
262+
DatasourceFilters: []string{dsName},
263+
Page: 1,
264+
Limit: 1,
265+
}
266+
267+
results, err := s.storageManager.GetSearchService().Search(params)
268+
if err != nil {
269+
log.Printf("Error fetching latest block from %s: %v", dsName, err)
270+
continue
271+
}
272+
273+
// Convert blocks to WebBlocks using the appropriate renderer
274+
if blocks, ok := results.Results[dsName]; ok && len(blocks) > 0 {
275+
for _, block := range blocks {
276+
webBlock := s.convertBlockToWebBlock(block)
277+
homeBlocks = append(homeBlocks, webBlock)
278+
}
279+
}
280+
}
281+
}
282+
248283
data := types.PageData{
249284
Title: "Ergs - Data Explorer",
250285
Datasources: datasources,
286+
HomeBlocks: homeBlocks,
251287
TotalBlocks: totalBlocks,
252288
ActiveDatasources: activeDatasources,
253289
OldestBlock: oldestBlock,

cmd/web/components/index.templ

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@ templ Index(data types.PageData) {
2828
/>
2929
<button type="submit" class="search-button">Search</button>
3030
</form>
31-
<div class="advanced-search-link">
32-
<a href="/search">Advanced Search</a>
33-
</div>
3431
</div>
32+
if len(data.HomeBlocks) > 0 {
33+
<div class="home-blocks-section">
34+
<h3>Latest Updates</h3>
35+
<div class="home-blocks">
36+
for _, block := range data.HomeBlocks {
37+
<div class="home-block">
38+
if block.FormattedText != "" {
39+
@templ.Raw(block.FormattedText)
40+
} else {
41+
<p>{ block.Text }</p>
42+
}
43+
</div>
44+
}
45+
</div>
46+
</div>
47+
}
3548
if len(data.Datasources) > 0 {
3649
<div class="stats-section">
3750
<h3>Quick Stats</h3>

cmd/web/components/index_templ.go

Lines changed: 67 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/web/components/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type PageData struct {
1010
SelectedDatasources []string // For search with multiple datasource selection
1111
Results map[string][]WebBlock
1212
FirehoseBlocks []WebBlock // Flat, globally time-ordered slice for firehose rendering
13+
HomeBlocks []WebBlock // Latest blocks from configured datasources for home page
1314
Datasources []DatasourceInfo
1415
TotalCount int
1516
Error string

cmd/web/static/style.css

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,28 @@ nav select:focus {
10391039
border-bottom-color: var(--accent);
10401040
}
10411041

1042+
.home-blocks-section {
1043+
margin: 2rem 0;
1044+
}
1045+
1046+
.home-blocks-section h3 {
1047+
margin-bottom: 1rem;
1048+
color: var(--text);
1049+
}
1050+
1051+
.home-blocks {
1052+
display: flex;
1053+
flex-direction: column;
1054+
gap: 1rem;
1055+
}
1056+
1057+
.home-block {
1058+
background: transparent;
1059+
border: none;
1060+
padding: 0;
1061+
margin: 0;
1062+
}
1063+
10421064
.stats-section {
10431065
text-align: center;
10441066
background: var(--surface-alt);

pkg/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Config struct {
1818
StorageDir string `toml:"storage_dir"`
1919
FetchInterval Duration `toml:"fetch_interval"`
2020
Importer *ImporterConfig `toml:"importer,omitempty"`
21+
Home *HomeConfig `toml:"home,omitempty"`
2122
Datasources map[string]DatasourceInfo `toml:"datasources"`
2223
EventSocketPath string `toml:"event_socket_path,omitempty"` // Optional Unix domain socket path for realtime warehouse->web events
2324
}
@@ -28,6 +29,10 @@ type ImporterConfig struct {
2829
Port string `toml:"port,omitempty"`
2930
}
3031

32+
type HomeConfig struct {
33+
Datasources string `toml:"datasources"` // Comma-separated list of datasource names
34+
}
35+
3136
type Duration struct {
3237
time.Duration
3338
}

pkg/config/config.toml.sample

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ storage_dir = '/home/user/.local/share/ergs'
1414
# If unspecified, real-time WebSocket firehose will not stream live updates.
1515
#event_socket_path = ''
1616

17+
# Home page configuration (optional)
18+
# Configure which datasources to display on the home page
19+
# The latest block from each configured datasource will be shown
20+
[home]
21+
# Comma-separated list of datasource names to display on home page
22+
# Example: datasources = 'github, rss, hackernews'
23+
# If not set or empty, no blocks will be displayed on the home page
24+
datasources = ''
1725

1826
# Importer API configuration
1927
# Used by both the importer API server (ergs importer) and importer datasource

0 commit comments

Comments
 (0)