1
0
mirror of synced 2026-01-19 00:06:24 -05:00
Files
docs/middleware/context.js
jmarlena 1fc4c3f68b Article restructuring for Sponsors landing page (#18772)
* Move article from github directory as a top-level product

* Update article titles

* Remove old -ing article titles

* Use older format for this PR

* Finish updating links for retitled articles

* Remove sponsors topic

* Add sponsors to index.md

* Create folder for map topic for sponsors

* Add integrating folder/category with super basic graphql article

* Add get started category/folder

* Update index.md

* Add articles to category folders and update all the links and check it out locally 🙏

* Fix space

* Fix set of broken links

* Update link in resuable

* Add the quickstart

* Add USD

* Add matching donations caveat

* fix ci failures

* Bringing back `-ing` to Sponsors titles, categories, & links (#18817)

* Bringing back -ing

* The one that got away

* Apply @ethanpalm's input

Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com>

Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com>

* Apply product input

* Apply suggestions from code review

Co-authored-by: Emily Gould <4822039+emilyistoofunky@users.noreply.github.com>

* Apply @emilyistoofunky's input

* Sponsors landing page design (#18774)

* Add sponsors to index.md as a top-level product

* Revamp the GitHub Sponsors landing page with article links

* remove merge tags

* add community section

* add sponsor descriptions

* swap repo for user

* remove prefix tag

* lint

* remove topic fix landing page

* Tweak articles on landing page

* Drop "account"

* Add quickstart

* Bigger, brighter, and shorter intro

* Possibly too long of an intro?

* fix quickstart link

* add guides page

* fix error for mismatch between title and filename

* use link over guid

* remove HTML from layout file (aligns to #18811)

* use variable for section title

* Add intro

* Remove beta

* Apply suggestions from code review

Co-authored-by: Emily Gould <4822039+emilyistoofunky@users.noreply.github.com>

* Apply suggestions from code review

* Integrate article changes and remove old TOC

* Fixing the commented out text to match other landing pages 👓

* Apply suggestions from code review

Co-authored-by: Emily Gould <4822039+emilyistoofunky@users.noreply.github.com>

* Switch up order of sidebar categories

* Add new text to landing page button

* Add topics and types

* Add the underscore

* Add some more topics

* fix `type:`

* Fix topics

* plural ftw

* hide learning paths when not defined

* lint

* Add quickstart to guides page

* remove unused sidebar links

* hide subsection title when learning tracks are not present

* Apply @emilyistoofunky's topics input

* Remove duplicated topics

* Events ftw

* typo

* Remove obsolete topics for now

* add some temporary duplicate topics

* Resolve Linter error

Co-authored-by: Rachael Sewell <rachmari@github.com>
Co-authored-by: Emily Gould <4822039+emilyistoofunky@users.noreply.github.com>

Co-authored-by: Rachael Sewell <rachmari@github.com>
Co-authored-by: Ethan Palm <56270045+ethanpalm@users.noreply.github.com>
Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
Co-authored-by: Emily Gould <4822039+emilyistoofunky@users.noreply.github.com>
2021-04-21 11:48:19 -07:00

78 lines
3.5 KiB
JavaScript

const languages = require('../lib/languages')
const enterpriseServerReleases = require('../lib/enterprise-server-releases')
const allVersions = require('../lib/all-versions')
const { productMap } = require('../lib/all-products')
const activeProducts = Object.values(productMap).filter(product => !product.wip && !product.hidden)
const {
getVersionStringFromPath,
getProductStringFromPath,
getCategoryStringFromPath,
getPathWithoutLanguage
} = require('../lib/path-utils')
const productNames = require('../lib/product-names')
const warmServer = require('../lib/warm-server')
const featureFlags = Object.keys(require('../feature-flags'))
const builtAssets = require('../lib/built-asset-urls')
const searchVersions = require('../lib/search/versions')
const nonEnterpriseDefaultVersion = require('../lib/non-enterprise-default-version')
// Supply all route handlers with a baseline `req.context` object
// Note that additional middleware in middleware/index.js adds to this context object
module.exports = async function contextualize (req, res, next) {
// Ensure that we load some data only once on first request
const { site, redirects, siteTree, pages: pageMap } = await warmServer()
req.context = {}
// make feature flag environment variables accessible in layouts
req.context.process = { env: {} }
featureFlags.forEach(featureFlagName => {
req.context.process.env[featureFlagName] = process.env[featureFlagName]
})
// define each context property explicitly for code-search friendliness
// e.g. searches for "req.context.page" will include results from this file
req.context.currentLanguage = req.language
req.context.currentVersion = getVersionStringFromPath(req.path)
req.context.currentProduct = getProductStringFromPath(req.path)
req.context.currentCategory = getCategoryStringFromPath(req.path)
req.context.productMap = productMap
req.context.activeProducts = activeProducts
req.context.allVersions = allVersions
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.path)
req.context.currentPath = req.path
req.context.query = req.query
req.context.languages = languages
req.context.productNames = productNames
req.context.enterpriseServerReleases = enterpriseServerReleases
req.context.enterpriseServerVersions = Object.keys(allVersions).filter(version => version.startsWith('enterprise-server@'))
req.context.redirects = redirects
req.context.site = site[req.language].site
req.context.siteTree = siteTree
req.context.pages = pageMap
if (productMap[req.context.currentProduct]) {
req.context.productCodeExamples = req.context.site.data.variables[`${productMap[req.context.currentProduct].id}_code_examples`]
req.context.productCommunityExamples = req.context.site.data.variables[`${productMap[req.context.currentProduct].id}_community_examples`]
req.context.productUserExamples = req.context.site.data.variables[`${productMap[req.context.currentProduct].id}_user_examples`]
}
// JS + CSS asset paths
req.context.builtAssets = builtAssets
// Object exposing selected variables to client
req.context.expose = JSON.stringify({
// Languages and versions for search
searchOptions: {
languages: Object.keys(languages),
versions: searchVersions,
nonEnterpriseDefaultVersion
},
// `|| undefined` won't show at all for production
airgap: Boolean(process.env.AIRGAP || req.cookies.AIRGAP) || undefined
})
if (process.env.AIRGAP || req.cookies.AIRGAP) req.context.AIRGAP = true
return next()
}