Skip to content

Commit a315c12

Browse files
committed
refactor: Replace duplicated related content partials
This commit replaces the hardware/related-content.html and software/related-events.html partials with a single shared/related-content.html partial. Logic to relate hardware and software was added.
1 parent 1d95012 commit a315c12

File tree

6 files changed

+152
-183
lines changed

6 files changed

+152
-183
lines changed

content/neuromorphic-computing/hardware/brainscales-2-universitat-heidelberg/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ summary: The BrainScaleS-2 is an accelerated spiking neuromorphic system-on-chip
3838
and non-spiking neural networks using hybrid techniques like surrogate gradients.
3939
title: BrainScaleS-2 — Heidelberg University
4040
type: neuromorphic-hardware
41+
software_tags: ['hxtorch','jaxsnn','pynn-brainscales2']
4142
---
4243

4344
The BrainScaleS-2 accelerated neuromorphic system is an integrated circuit architecture for emulating biologically-inspired spiking neural networks. It was developed by researchers at the Heidelberg University and collaborators. Key features of the BrainScaleS-2 system include:

layouts/neuromorphic-hardware/single.html

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,8 @@
2222
<div class="content mb-10">
2323
{{ .Content }}
2424
</div>
25-
{{/* Related Content via hardware_tags */}}
26-
{{ $hardwareSlug := .File.Dir | path.Base }}
27-
{{ $relatedContent := slice }}
28-
{{ range site.RegularPages }}
29-
{{ $contentPage := . }}
30-
{{ with .Params.hardware_tags }}
31-
{{ if in . $hardwareSlug }}
32-
{{ $relatedContent = $relatedContent | append $contentPage }}
33-
{{ end }}
34-
{{ end }}
35-
{{ end }}
36-
{{ $relatedContent = sort $relatedContent "Date" "desc" }}
37-
{{ partial "hardware/related-content.html" $relatedContent }}
25+
26+
{{ partial "shared/related-content.html" . }}
3827

3928
<div class="max-w-4xl mx-auto mt-12 mb-16">
4029
{{ partial "components/content-contribute-cta.html" (dict

layouts/neuromorphic-software/single.html

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@
88
{{ .Content }}
99
</article>
1010

11-
{{ $softwareSlug := .File.Dir | path.Base }}
12-
{{ $relatedContent := slice }}
13-
{{ range site.RegularPages }}
14-
{{ $contentPage := . }}
15-
{{ with .Params.software_tags }}
16-
{{ if in . $softwareSlug }}
17-
{{ $relatedContent = $relatedContent | append $contentPage }}
18-
{{ end }}
19-
{{ end }}
20-
{{ end }}
21-
{{ $relatedContent = sort $relatedContent "Date" "desc" }}
22-
{{ partial "software/related-events.html" $relatedContent }}
11+
{{ partial "shared/related-content.html" . }}
2312

2413
{{ partial "components/content-contribute-cta.html" (dict
2514
"page_context" .

layouts/partials/hardware/related-content.html

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{{ $page_context := . }}
2+
{{ $related_items := slice }}
3+
4+
{{ $current_type := $page_context.Type }}
5+
{{ $current_slug := path.Base $page_context.File.Dir }}
6+
{{ $current_title := $page_context.Title }}
7+
8+
9+
{{/* --- Part 1: Find related content (blog, events) that tag this page --- */}}
10+
11+
{{ $tag_param_key := "" }}
12+
{{ if eq $current_type "neuromorphic-hardware" }}
13+
{{ $tag_param_key = ".Params.hardware_tags" }}
14+
{{ else if eq $current_type "neuromorphic-software" }}
15+
{{ $tag_param_key = ".Params.software_tags" }}
16+
{{ end }}
17+
18+
{{ if ne $tag_param_key "" }}
19+
{{ $tagged_pages := where site.RegularPages $tag_param_key "intersect" (slice $current_slug) }}
20+
{{ range $tagged_pages }}
21+
{{ $related_items = $related_items | append . }}
22+
{{ end }}
23+
{{ end }}
24+
25+
26+
{{/* --- Part 2: Find related hardware/software (bidirectional linking) --- */}}
27+
28+
{{ if eq $current_type "neuromorphic-hardware" }}
29+
{{/* I am a hardware page. Find software I support using my `software_tags` */}}
30+
{{ with .Params.software_tags }}
31+
{{ $software_slugs_to_find := . }}
32+
{{ $all_software_pages := where site.RegularPages "Type" "neuromorphic-software" }}
33+
{{ range $software_page := $all_software_pages }}
34+
{{ $software_slug := path.Base $software_page.File.Dir }}
35+
{{ if in $software_slugs_to_find $software_slug }}
36+
{{ $related_items = $related_items | append $software_page }}
37+
{{ end }}
38+
{{ end }}
39+
{{ end }}
40+
41+
{{ else if eq $current_type "neuromorphic-software" }}
42+
{{/* I am a software page. Find hardware that supports me. */}}
43+
{{ $hardware_pages := where site.RegularPages "Type" "neuromorphic-hardware" }}
44+
{{ range where $hardware_pages ".Params.software_tags" "intersect" (slice $current_slug) }}
45+
{{ $related_items = $related_items | append . }}
46+
{{ end }}
47+
{{ end }}
48+
49+
{{/* --- Finalize and Render --- */}}
50+
{{/* Deduplicate without uniqBy for older Hugo versions */}}
51+
{{ $unique_related_items := slice }}
52+
{{ $seen_permalinks := slice }}
53+
{{ range $related_items }}
54+
{{ if not (in $seen_permalinks .Permalink) }}
55+
{{ $unique_related_items = $unique_related_items | append . }}
56+
{{ $seen_permalinks = $seen_permalinks | append .Permalink }}
57+
{{ end }}
58+
{{ end }}
59+
{{ $sorted_related_items := sort $unique_related_items "Date" "desc" }}
60+
61+
62+
{{ if $sorted_related_items }}
63+
<div class="related-content-section mt-12 pt-8 pb-8">
64+
<h2 class="text-3xl font-bold mb-8">Related Content, Events & Resources</h2>
65+
66+
<div class="space-y-6">
67+
{{ range $item := $sorted_related_items }}
68+
<div class="timeline-item-content">
69+
<div class="flex flex-col md:flex-row items-start gap-5">
70+
71+
{{/* Thumbnail Column */}}
72+
<div class="flex-shrink-0 w-full md:w-40 text-center">
73+
<a href="{{ $item.RelPermalink }}">
74+
{{ $image_param := $item.Params.image }}
75+
{{ $img_path := "" }}
76+
{{ $img_alt := $item.Title }}
77+
78+
{{ if $image_param }}
79+
{{ $img_path_cleaned := strings.TrimPrefix "/" $image_param }}
80+
{{ $resource := "" }}
81+
{{ with $item.Resources.GetMatch $image_param }}
82+
{{ $resource = . }}
83+
{{ else }}
84+
{{ with resources.Get $img_path_cleaned }}
85+
{{ $resource = . }}
86+
{{ end }}
87+
{{ end }}
88+
89+
{{ if $resource }}
90+
{{ $img_path = ($resource.Fill "160x90 Lanczos").RelPermalink }}
91+
{{ else if fileExists (printf "static/%s" $img_path_cleaned) }}
92+
{{ $img_path = $image_param | relURL }}
93+
{{ end }}
94+
{{ end }}
95+
96+
{{ if not $img_path }}
97+
{{ with resources.Get "images/workshop-thumbnail-default.png" }}
98+
{{ $img_path = (.Fill "160x90 Lanczos").RelPermalink }}
99+
{{ $img_alt = "Default Open Neuromorphic Event Thumbnail" }}
100+
{{ end }}
101+
{{ end }}
102+
103+
{{ if $img_path }}
104+
<img src="{{ $img_path }}" alt="{{ $img_alt }}" class="w-full h-auto rounded-md object-cover">
105+
{{ else }}
106+
<div class="w-full h-[90px] bg-gray-200 dark:bg-darkmode-theme-dark rounded-md flex items-center justify-center">
107+
{{ partial "icon.html" (dict "style" "regular" "name" "images" "class" "text-4xl text-gray-400") }}
108+
</div>
109+
{{ end }}
110+
</a>
111+
</div>
112+
113+
{{/* Content Column */}}
114+
<div class="flex-grow">
115+
<div class="flex justify-between items-start gap-4">
116+
<div>
117+
<h4 class="text-xl font-semibold mb-1">
118+
<a href="{{ $item.RelPermalink }}" class="text-dark dark:text-darkmode-dark hover:text-primary dark:hover:text-darkmode-primary">{{ $item.Title }}</a>
119+
</h4>
120+
{{ with $item.Params.date }}
121+
<p class="text-sm text-gray-500 dark:text-gray-400">
122+
{{ .Format "January 2, 2006" }}
123+
</p>
124+
{{ end }}
125+
</div>
126+
<span class="timeline-item-badge flex-shrink-0">
127+
{{- $item_type := "" -}}
128+
{{- if eq $item.Type "neuromorphic-hardware" -}}
129+
{{- $item_type = "Hardware" -}}
130+
{{- else if eq $item.Type "neuromorphic-software" -}}
131+
{{- $item_type = "Software" -}}
132+
{{- else -}}
133+
{{- $item_type = $item.Type | default $item.Section | humanize | title -}}
134+
{{- end -}}
135+
{{- $item_type -}}
136+
</span>
137+
</div>
138+
{{ if $item.Description }}
139+
<p class="text-gray-600 dark:text-gray-400 mt-3 text-sm">{{ $item.Description | truncate 150 }}</p>
140+
{{ end }}
141+
</div>
142+
143+
</div>
144+
</div>
145+
{{ end }}
146+
</div>
147+
</div>
148+
{{ end }}

layouts/partials/software/related-events.html

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)