Skip to content

Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.

2.6 KB
Raw Blame
import type { Graph } from "schema-dts";

import { PROD_WEBSITE_URL, HOW_IT_WORKS_VIDEOS } from "@/config";
import { buildBreadcrumbList } from "@/lib/seo/breadcrumb";
import {
  JSON_LD_IDS,
  pageBreadcrumbId,
  pageWebPageId,
} from "@/lib/seo/json-ld-ids";

const PAGE_TITLE = "How EasyInvoicePDF Works | Video Tutorials";

/** Also the page's meta description, so search results and the JSON-LD say the same. */
export const HOW_IT_WORKS_PAGE_DESCRIPTION =
  "Watch short video tutorials on creating invoices, saving seller and buyer details, customizing tax, adding discounts, and weekly invoices with EasyInvoicePDF.";

export function buildHowItWorksJsonLd(baseUrl = PROD_WEBSITE_URL): Graph {
  const pageUrl = `${baseUrl}/how-it-works`;

  const videoItems = HOW_IT_WORKS_VIDEOS.map((video, index) => {
    return {
      "@type": "ListItem" as const,
      position: index + 1,
      item: {
        "@type": "VideoObject" as const,
        name: video.title,
        description: video.description,
        uploadDate: video.uploadDate,
        duration: toIsoDuration(video.durationSeconds),
        thumbnailUrl: video.thumbnailUrl,
        // `embedUrl` alone: `contentUrl` is for the video file's own bytes, which
        // YouTube never hands out, and the watch page is what it must not be
        embedUrl: video.embedUrl,
        url: `${pageUrl}#${video.id}`,
        publisher: {
          "@type": "Organization" as const,
          name: "EasyInvoicePDF",
          url: baseUrl,
        },
      },
    };
  });

  return {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "WebPage",
        "@id": pageWebPageId(pageUrl),
        url: pageUrl,
        name: PAGE_TITLE,
        description: HOW_IT_WORKS_PAGE_DESCRIPTION,
        inLanguage: "en",
        isPartOf: {
          "@id": JSON_LD_IDS.website,
        },
        breadcrumb: {
          "@id": pageBreadcrumbId(pageUrl),
        },
        mainEntity: {
          "@type": "ItemList",
          "@id": `${pageUrl}#tutorials`,
          name: "EasyInvoicePDF video tutorials",
          itemListElement: videoItems,
        },
      },
      buildBreadcrumbList({
        pageUrl,
        items: [
          { name: "Start Invoicing", item: `${baseUrl}/` },
          { name: "How it works" },
        ],
      }),
    ],
  };
}

/** `79` → `"PT1M19S"`, the ISO 8601 form schema.org's `duration` takes. */
function toIsoDuration(totalSeconds: number) {
  const minutes = Math.floor(totalSeconds / 60);
  const seconds = totalSeconds % 60;

  return minutes > 0 ? `PT${minutes}M${seconds}S` : `PT${seconds}S`;
}