Skip to content

Commit

Permalink
remove activeProductSlugs, use productSlugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zchsh committed Sep 13, 2024
1 parent fced1d4 commit e86a189
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
6 changes: 3 additions & 3 deletions scripts/warm-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from 'lib/learn-client/api/collection'
import { splitProductFromFilename } from 'views/tutorial-view/utils'
import config from '../config/base.json'
import { activeProductSlugs } from 'lib/products'
import { productSlugs } from 'lib/products'
import { ProductSlug } from 'types/products'

const DEV_PORTAL_URL = config.dev_dot.canonical_base_url
Expand All @@ -27,7 +27,7 @@ const fetch = createFetch(null, { timeout: 900 * 1000 })
async function warmDeveloperDocsCache() {
const url = new URL('/api/revalidate', DEV_PORTAL_URL)

for (const productSlug of activeProductSlugs) {
for (const productSlug of productSlugs) {
const body = JSON.stringify({ product: productSlug })

try {
Expand Down Expand Up @@ -93,7 +93,7 @@ async function getTutorialUrlsToCache(product: ProductSlug): Promise<string[]> {
try {
const tutorialUrls = (
await Promise.all(
activeProductSlugs.map((product: ProductSlug) =>
productSlugs.map((product: ProductSlug) =>
getTutorialUrlsToCache(product)
)
)
Expand Down
35 changes: 23 additions & 12 deletions src/lib/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,29 @@ import { Product, ProductName, ProductSlug } from 'types/products'
/**
* A map of product slugs to their proper noun names.
*
* 🚨 NOTE: the order of this object matters for the Home page.
* 🚨 NOTE: the order of the keys in this object matters. It determines
* the order in which products are displayed in certain locations.
* Specifically, with iterate over the `Object.keys()` of this object
* in the following places:
*
* - generate-top-level-sub-nav-items (for the main nav)
* - getStaticPaths (for /<product>/docs landing pages)
* - VALID_PRODUCT_SLUGS_FOR_FILTERING (for Tutorials Library sidebar filter)
* - getTutorialLandingPaths (for tutorials included in the sitemap)
* - getStaticPaths (for individual tutorials pages)
* - generateProductTutorialHomePaths (for /<product>/tutorials landing pages)
*
* We already have at least one instance (for HCP Vault secrets) where we've
* avoided adding to this constant because of how it's intertwined with other
* purposes. It might make sense for us to refactor some code so that we're
* only ever using this constant as a way to get the product name from a given
* product slug. Specifically:
*
* - In Tutorials instances, maybe we could fetch from the Tutorials API
* to determine which products are available for filtering or appropriate
* to include in the sitemap, rather that using a hard-coded constant?
* - In
*/
const productSlugsToNames: { [slug in ProductSlug]: ProductName } = {
hcp: 'HashiCorp Cloud Platform',
Expand Down Expand Up @@ -54,16 +76,6 @@ function isProductSlug(string: string): string is ProductSlug {
*/
const productSlugs = Object.keys(productSlugsToNames) as ProductSlug[]

/**
* An array of product slugs which are "active" on the site. Currently all products.
*
* TODO: deprecate this, replace all uses of `activeProductSlugs` with
* `productSlugs`, then remove this constant. This was used to migrate off
* of the dot-io sites and onto developer.hashicorp.com, that migration
* is fully complete, so we no longer need this extra layer.
*/
const activeProductSlugs = productSlugs

/**
* Generates an array of Product objects from `productSlugs`.
*/
Expand All @@ -73,7 +85,6 @@ const products: Product[] = productSlugs.map((slug: ProductSlug) => {
})

export {
activeProductSlugs,
isProductSlug,
products,
productSlugs,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/sitemap/tutorials-content-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import { getAllCollections } from 'lib/learn-client/api/collection'
import { SectionOption } from 'lib/learn-client/types'
import { activeProductSlugs } from 'lib/products'
import { productSlugs } from 'lib/products'
import tutorialMap from 'data/_tutorial-map.generated.json'
import { ProductSlug } from 'types/products'
import { getCollectionSlug } from 'views/collection-view/helpers'
import { makeSitemapField } from './helpers'
import { Collection as ClientCollection } from 'lib/learn-client/types'

function getTutorialLandingPaths(): string[] {
const activeSlugs = activeProductSlugs.map(
const activeSlugs = productSlugs.map(
(productSlug: ProductSlug) => `${productSlug}/tutorials`
)
const sectionOptionsWithLandingPage = Object.values(SectionOption).filter(
Expand Down
4 changes: 2 additions & 2 deletions src/pages/[productSlug]/docs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import { ProductSlug } from 'types/products'
import { getStaticProps } from 'views/product-root-docs-path-landing/server'
import ProductRootDocsPathLanding from 'views/product-root-docs-path-landing'
import { activeProductSlugs } from 'lib/products'
import { productSlugs } from 'lib/products'

/**
* Generates the paths for all /:productSlug/docs routes.
*/
const getStaticPaths = async () => {
const paths = activeProductSlugs.map((productSlug: ProductSlug) => ({
const paths = productSlugs.map((productSlug: ProductSlug) => ({
params: { productSlug },
}))

Expand Down
4 changes: 2 additions & 2 deletions src/pages/[productSlug]/tutorials/[...tutorialSlug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
getTutorialPagePaths,
getTutorialPageProps,
} from 'views/tutorial-view/server'
import { activeProductSlugs } from 'lib/products'
import { productSlugs } from 'lib/products'

async function getStaticPaths(): Promise<
GetStaticPathsResult<TutorialPagePaths['params']>
Expand All @@ -38,7 +38,7 @@ async function getStaticPaths(): Promise<
try {
paths = (
await Promise.all(
activeProductSlugs.map(async (productSlug) => {
productSlugs.map(async (productSlug) => {
// fetch paths from analytics for each product
const analyticsPaths = await getStaticPathsFromAnalytics<
TutorialPagePaths['params']
Expand Down
4 changes: 2 additions & 2 deletions src/pages/[productSlug]/tutorials/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import {
} from 'views/product-tutorials-view/server'
import ProductTutorialsView from 'views/product-tutorials-view'
import { cachedGetProductData } from 'lib/get-product-data'
import { activeProductSlugs } from 'lib/products'
import { productSlugs } from 'lib/products'

/**
* Based on the array of beta product slugs,
* generate each product tutorials route
* i.e. /vault/tutorials
*/
function generateProductTutorialHomePaths() {
const paths = activeProductSlugs.map((productSlug: ProductSlug) => ({
const paths = productSlugs.map((productSlug: ProductSlug) => ({
params: { productSlug },
}))
return paths
Expand Down

0 comments on commit e86a189

Please sign in to comment.