All files / owid-grapher/site FrontPage.tsx

13.9% Statements 26/187
100% Branches 0/0
0% Functions 0/2
13.9% Lines 26/187

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 4031x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x 1x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
import * as React from "react"
import { Head } from "./Head"
import { SiteHeader } from "./SiteHeader"
import { SiteFooter } from "./SiteFooter"
import { faRss } from "@fortawesome/free-solid-svg-icons/faRss"
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight"
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons/faExternalLinkAlt"
import { faAngleDoubleDown } from "@fortawesome/free-solid-svg-icons/faAngleDoubleDown"
import { faTwitter } from "@fortawesome/free-brands-svg-icons/faTwitter"
import { faFacebookSquare } from "@fortawesome/free-brands-svg-icons/faFacebookSquare"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faArrowRight } from "@fortawesome/free-solid-svg-icons/faArrowRight"
import {
    NewsletterSubscriptionForm,
    NewsletterSubscriptionContext,
} from "../site/NewsletterSubscription"
import {
    CategoryWithEntries,
    EntryNode,
    FullPost,
} from "../clientUtils/owidTypes"
import PostCard from "./PostCard/PostCard"
 
const splitOnLastWord = (str: string) => {
    const endIndex = (str.lastIndexOf(" ") as number) + 1
    return {
        start: endIndex === 0 ? "" : str.substring(0, endIndex),
        end: str.substring(endIndex),
    }
}
 
export const FrontPage = (props: {
    entries: CategoryWithEntries[]
    posts: FullPost[]
    totalCharts: number
    baseUrl: string
}) => {
    const { entries, posts, totalCharts, baseUrl } = props

    // Structured data for google
    const structuredMarkup = {
        "@context": "https://schema.org",
        "@type": "WebSite",
        url: baseUrl,
        potentialAction: {
            "@type": "SearchAction",
            target: `${baseUrl}/search?q={search_term_string}`,
            "query-input": "required name=search_term_string",
        },
    }

    const renderEntry = (entry: EntryNode, categorySlug: string) => {
        const { start: titleStart, end: titleEnd } = splitOnLastWord(
            entry.title
        )
        return (
            <a
                key={entry.slug}
                href={`/${entry.slug}`}
                className={`entry-item-container ${categorySlug}-color`}
                data-track-note="homepage-entries"
            >
                <div className="entry-item">
                    <div className="top">
                        {entry.kpi && (
                            <div
                                className="kpi"
                                dangerouslySetInnerHTML={{
                                    __html: entry.kpi,
                                }}
                            />
                        )}
                        <p className="excerpt">{entry.excerpt}</p>
                    </div>
                    <div className="bottom">
                        <h5>
                            {titleStart}
                            <span>
                                {titleEnd}
                                <FontAwesomeIcon icon={faArrowRight} />
                            </span>
                        </h5>
                    </div>
                </div>
            </a>
        )
    }

    return (
        <html>
            <Head canonicalUrl={baseUrl} baseUrl={baseUrl}>
                <script
                    type="application/ld+json"
                    dangerouslySetInnerHTML={{
                        __html: JSON.stringify(structuredMarkup),
                    }}
                />
            </Head>
            <body className="FrontPage">
                <SiteHeader baseUrl={baseUrl} />

                <section className="homepage-masthead">
                    <div className="wrapper">
                        <h1>
                            Research and data to make progress against the
                            world’s largest problems
                        </h1>
                        <a
                            href="#entries"
                            className="see-all"
                            data-smooth-scroll
                            data-track-note="homepage-scroll"
                        >
                            Scroll to all our articles
                            <span className="icon">
                                <FontAwesomeIcon icon={faAngleDoubleDown} />
                            </span>
                        </a>
                        <p>{totalCharts} charts across 297 topics</p>
                        <p>All free: open access and open source</p>
                    </div>
                </section>

                <section className="homepage-coverage">
                    <div className="wrapper">
                        <div className="inner-wrapper">
                            <div className="owid-row owid-spacing--4">
                                <div className="owid-col owid-col--lg-2">
                                    <section>
                                        <h3 className="align-center">
                                            Trusted in{" "}
                                            <strong>research and media</strong>
                                        </h3>
                                        <a
                                            href="/about/coverage#coverage"
                                            className="coverage-link"
                                            data-track-note="homepage-trust"
                                        >
                                            <img
                                                src={`${baseUrl}/media-logos-wide.png`}
                                                alt="Logos of the publications that have used our content"
                                            />
                                            <div className="hover-note">
                                                <p>
                                                    Find out how our work is
                                                    used by journalists and
                                                    researchers
                                                </p>
                                            </div>
                                        </a>
                                    </section>
                                    <section>
                                        <h3 className="align-center">
                                            Used in <strong>teaching</strong>
                                        </h3>
                                        <a
                                            href="/about/coverage#teaching"
                                            className="coverage-link"
                                            data-track-note="homepage-trust"
                                        >
                                            <img
                                                src={`${baseUrl}/university-logos-wide.png`}
                                                alt="Logos of the universities that have used our content"
                                            />
                                            <div className="hover-note">
                                                <p>
                                                    Find out how our work is
                                                    used in teaching
                                                </p>
                                            </div>
                                        </a>
                                    </section>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>

                <section className="homepage-posts">
                    <div className="wrapper">
                        <div className="owid-row">
                            <div className="owid-col flex-row">
                                <div className="homepage-posts--explainers">
                                    <div className="header">
                                        <h2>Latest publications</h2>
                                    </div>
                                    <ul>
                                        {posts.slice(0, 6).map((post) => (
                                            <li key={post.slug}>
                                                <PostCard post={post} />
                                            </li>
                                        ))}
                                    </ul>
                                    <div className="see-all">
                                        <a
                                            href="/blog"
                                            data-track-note="homepage-see-all-explainers"
                                        >
                                            <div className="label">
                                                See all posts
                                            </div>
                                            <div className="icon">
                                                <FontAwesomeIcon
                                                    icon={faAngleRight}
                                                />
                                            </div>
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
 
                <section className="homepage-subscribe" id="subscribe">
                    <div className="wrapper">
                        <div className="owid-row">
                            <div className="owid-col owid-col--lg-2 flex-row owid-padding-bottom--sm-3">
                                <div className="newsletter-subscription">
                                    <div className="box">
                                        <h2>Subscribe to our newsletter</h2>
                                        <div className="root">
                                            {/* Hydrated in runSiteTools() */}
                                            <NewsletterSubscriptionForm
                                                context={
                                                    NewsletterSubscriptionContext.Homepage
                                                }
                                            />
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div className="owid-col owid-col--lg-1">
                                <div className="homepage-subscribe--social-media">
                                    <div className="shaded-box">
                                        <h2>Follow us</h2>
                                        <div className="list">
                                            <a
                                                href="https://twitter.com/ourworldindata"
                                                className="list-item"
                                                title="Twitter"
                                                target="_blank"
                                                rel="noopener noreferrer"
                                                data-track-note="homepage-follow-us"
                                            >
                                                <div className="icon">
                                                    <FontAwesomeIcon
                                                        icon={faTwitter}
                                                    />
                                                </div>
                                                <div className="label">
                                                    Twitter
                                                </div>
                                            </a>
                                            <a
                                                href="https://facebook.com/ourworldindata"
                                                className="list-item"
                                                title="Facebook"
                                                target="_blank"
                                                rel="noopener noreferrer"
                                                data-track-note="homepage-follow-us"
                                            >
                                                <div className="icon">
                                                    <FontAwesomeIcon
                                                        icon={faFacebookSquare}
                                                    />
                                                </div>
                                                <div className="label">
                                                    Facebook
                                                </div>
                                            </a>
                                            <a
                                                href="/feed"
                                                className="list-item"
                                                title="RSS"
                                                target="_blank"
                                                data-track-note="homepage-follow-us"
                                            >
                                                <div className="icon">
                                                    <FontAwesomeIcon
                                                        icon={faRss}
                                                    />
                                                </div>
                                                <div className="label">
                                                    RSS Feed
                                                </div>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
 
                <section className="homepage-projects">
                    <div className="wrapper">
                        <div className="list">
                            <a
                                href="https://sdg-tracker.org"
                                className="list-item"
                                data-track-note="homepage-projects"
                            >
                                <div className="icon-left">
                                    <img
                                        src={`${baseUrl}/sdg-wheel.png`}
                                        alt="SDG Tracker logo"
                                        loading="lazy"
                                    />
                                </div>
                                <div className="content">
                                    <h3>
                                        Sustainable Development Goals Tracker
                                    </h3>
                                    <p>
                                        Is the world on track to reach the
                                        Sustainable Development Goals?
                                    </p>
                                </div>
                                <div className="icon-right">
                                    <FontAwesomeIcon icon={faExternalLinkAlt} />
                                </div>
                            </a>
                            <a
                                href="/teaching"
                                className="list-item"
                                data-track-note="homepage-projects"
                            >
                                <div className="icon-left">
                                    <img
                                        src={`${baseUrl}/teaching-hub.svg`}
                                        alt="Teaching Hub logo"
                                        loading="lazy"
                                    />
                                </div>
                                <div className="content">
                                    <h3>Teaching Hub</h3>
                                    <p>
                                        Slides, research, and visualizations for
                                        teaching and learning about global
                                        development
                                    </p>
                                </div>
                                <div className="icon-right">
                                    <FontAwesomeIcon icon={faExternalLinkAlt} />
                                </div>
                            </a>
                        </div>
                    </div>
                </section>
 
                <section id="entries" className="homepage-entries">
                    <div className="wrapper">
                        <h2>
                            All our articles on global problems and global
                            changes
                        </h2>
                        {entries.map((category) => (
                            <div
                                key={category.slug}
                                className="category-wrapper"
                            >
                                <h3
                                    className={`${category.slug}-color`}
                                    id={category.slug}
                                >
                                    {category.name}
                                </h3>
                                {!!category.entries.length && (
                                    <div className="category-entries">
                                        {category.entries.map((entry) =>
                                            renderEntry(entry, category.slug)
                                        )}
                                    </div>
                                )}
                                {category.subcategories.map((subcategory) => (
                                    <div key={subcategory.slug}>
                                        <h4
                                            className={`${category.slug}-color`}
                                        >
                                            {subcategory.name}
                                        </h4>
                                        <div className="category-entries">
                                            {subcategory.entries.map((entry) =>
                                                renderEntry(
                                                    entry,
                                                    category.slug
                                                )
                                            )}
                                        </div>
                                    </div>
                                ))}
                            </div>
                        ))}
                    </div>
                </section>
 
                <SiteFooter baseUrl={baseUrl} />
            </body>
        </html>
    )
}