|
5 | 5 | from core.constants import SLACK_MEMBER_COUNT |
6 | 6 | from core.models import HomepageSettings |
7 | 7 | from core.templatetags.custom_static import large_static |
8 | | -from libraries.models import LibraryVersion, Tier |
9 | | -from libraries.utils import build_library_intro_context |
| 8 | +from libraries.models import FEATURED_LIBRARY_TIERS, Library, LibraryVersion |
| 9 | +from libraries.utils import build_library_intro_context, get_documentation_url |
10 | 10 | from news.models import Entry |
11 | 11 | from versions.models import Version |
12 | 12 |
|
13 | | -# Fallback code snippet shown on the Get Started card when no featured |
14 | | -# library snippet is available. TODO: replace with a proper empty state. |
15 | | -HELLO_WORLD_SNIPPET = """#include <iostream> |
16 | | -int main() |
17 | | -{ |
18 | | - std::cout << "Hello, Boost."; |
19 | | -}""" |
20 | | - |
21 | 13 | # Hero illustration for the V3 homepage. |
22 | 14 | HERO_LEGACY_IMAGE_URL_LIGHT = large_static("img/v3/home-page/heros.png") |
23 | 15 | HERO_LEGACY_IMAGE_URL_DARK = large_static("img/v3/home-page/heros_light.png") |
@@ -45,7 +37,7 @@ def get_v3_featured_library(): |
45 | 37 | return ( |
46 | 38 | LibraryVersion.objects.filter( |
47 | 39 | version=latest_version, |
48 | | - library__tier__in=[Tier.FLAGSHIP, Tier.CORE], |
| 40 | + library__tier__in=FEATURED_LIBRARY_TIERS, |
49 | 41 | ) |
50 | 42 | .order_by("?") |
51 | 43 | .first() |
@@ -152,17 +144,62 @@ def build_join_developers_links(): |
152 | 144 | ] |
153 | 145 |
|
154 | 146 |
|
155 | | -def build_get_started_code(): |
156 | | - """The Get Started code card. Hardcoded for now; a redesign of this |
157 | | - component is tracked in a separate PR. |
| 147 | +def build_library_highlight_carousel(limit=3): |
| 148 | + """Per-slide content for the homepage 'Explore battle tested libraries' |
| 149 | + carousel. |
| 150 | +
|
| 151 | + Shows the libraries an editor curated in HomepageSettings first (in random |
| 152 | + order); when fewer than `limit` are curated, the remaining slots are filled |
| 153 | + with random flagship/core libraries in the latest release. Returns a list |
| 154 | + of dicts (name, category_tags, description, added_in_version, docs_url); |
| 155 | + empty when no candidate library exists. |
158 | 156 | """ |
159 | | - return { |
160 | | - "heading": "Get started with our libraries", |
161 | | - "code": HELLO_WORLD_SNIPPET, |
162 | | - "language": "cpp", |
163 | | - "library_slug": "", |
| 157 | + latest = Version.objects.most_recent() |
| 158 | + libraries = list( |
| 159 | + HomepageSettings.load() |
| 160 | + .highlighted_libraries.prefetch_related("categories") |
| 161 | + .order_by("?") |
| 162 | + ) |
| 163 | + |
| 164 | + remaining_slots = limit - len(libraries) |
| 165 | + if remaining_slots > 0: |
| 166 | + libraries += list( |
| 167 | + Library.objects.filter( |
| 168 | + tier__in=FEATURED_LIBRARY_TIERS, |
| 169 | + library_version__version=latest, |
| 170 | + ) |
| 171 | + .exclude(id__in=[lib.id for lib in libraries]) |
| 172 | + .distinct() |
| 173 | + .prefetch_related("categories") |
| 174 | + .order_by("?")[:remaining_slots] |
| 175 | + ) |
| 176 | + if not libraries: |
| 177 | + return [] |
| 178 | + |
| 179 | + library_versions = { |
| 180 | + lv.library_id: lv |
| 181 | + for lv in LibraryVersion.objects.filter(library__in=libraries, version=latest) |
164 | 182 | } |
165 | 183 |
|
| 184 | + slides = [] |
| 185 | + for library in libraries: |
| 186 | + lv = library_versions.get(library.id) |
| 187 | + first_version = library.first_boost_version |
| 188 | + slides.append( |
| 189 | + { |
| 190 | + "name": library.display_name_short, |
| 191 | + "category_tags": library.category_tags, |
| 192 | + "description": ( |
| 193 | + (lv.description if lv else None) or library.description or "" |
| 194 | + ), |
| 195 | + "added_in_version": ( |
| 196 | + first_version.display_name if first_version else "" |
| 197 | + ), |
| 198 | + "docs_url": get_documentation_url(lv, latest=True) if lv else "", |
| 199 | + } |
| 200 | + ) |
| 201 | + return slides |
| 202 | + |
166 | 203 |
|
167 | 204 | def build_library_intro(): |
168 | 205 | """Library Intro card content for the V3 homepage, or None if no |
|
0 commit comments