Revert "Fix homepage versions dropdown" (#20087)
This commit is contained in:
@@ -10,7 +10,7 @@ import { useVersion } from './hooks/useVersion'
|
|||||||
|
|
||||||
export const SidebarNav = () => {
|
export const SidebarNav = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { error, relativePath } = useMainContext()
|
const { error, relativePath, isHomepageVersion } = useMainContext()
|
||||||
const { t } = useTranslation('header')
|
const { t } = useTranslation('header')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -39,7 +39,7 @@ export const SidebarNav = () => {
|
|||||||
<nav>
|
<nav>
|
||||||
{error === '404' || relativePath === 'index.md' ? (
|
{error === '404' || relativePath === 'index.md' ? (
|
||||||
<ul className="sidebar-products mt-4">
|
<ul className="sidebar-products mt-4">
|
||||||
{<AllProductsLink />}
|
{!isHomepageVersion && <AllProductsLink />}
|
||||||
<SidebarHomepage />
|
<SidebarHomepage />
|
||||||
</ul>
|
</ul>
|
||||||
) : (
|
) : (
|
||||||
@@ -66,12 +66,12 @@ export const SidebarNav = () => {
|
|||||||
const SidebarHomepage = () => {
|
const SidebarHomepage = () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { currentVersion } = useVersion()
|
const { currentVersion } = useVersion()
|
||||||
const { activeProducts } = useMainContext()
|
const { activeProducts, isHomepageVersion } = useMainContext()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{activeProducts.map((product) => {
|
{activeProducts.map((product) => {
|
||||||
if (!product.versions?.includes(currentVersion) && !product.external) {
|
if (!product.versions?.includes(currentVersion) && !isHomepageVersion) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ export const ArticleVersionPicker = () => {
|
|||||||
</summary>
|
</summary>
|
||||||
<Dropdown.Menu direction="sw">
|
<Dropdown.Menu direction="sw">
|
||||||
{(page.permalinks || []).map((permalink) => {
|
{(page.permalinks || []).map((permalink) => {
|
||||||
|
if (permalink.pageVersion === 'homepage') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown.Item key={permalink.href}>
|
<Dropdown.Item key={permalink.href}>
|
||||||
<Link href={permalink.href}>{permalink.pageVersionTitle}</Link>
|
<Link href={permalink.href}>{permalink.pageVersionTitle}</Link>
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export const getMainContextFromRequest = (req: any): MainContextT => {
|
|||||||
activeProducts: req.context.activeProducts,
|
activeProducts: req.context.activeProducts,
|
||||||
currentProduct: req.context.productMap[req.context.currentProduct] || null,
|
currentProduct: req.context.productMap[req.context.currentProduct] || null,
|
||||||
currentLayoutName: req.context.currentLayoutName,
|
currentLayoutName: req.context.currentLayoutName,
|
||||||
isHomepageVersion: req.context.page?.documentType === 'homepage',
|
isHomepageVersion: req.context.currentVersion === 'homepage',
|
||||||
error: req.context.error ? req.context.error.toString() : '',
|
error: req.context.error ? req.context.error.toString() : '',
|
||||||
data: {
|
data: {
|
||||||
ui: req.context.site.data.ui,
|
ui: req.context.site.data.ui,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { ChevronDownIcon } from '@primer/octicons-react'
|
|||||||
import { Link } from 'components/Link'
|
import { Link } from 'components/Link'
|
||||||
import { useMainContext } from 'components/context/MainContext'
|
import { useMainContext } from 'components/context/MainContext'
|
||||||
import { useVersion } from 'components/hooks/useVersion'
|
import { useVersion } from 'components/hooks/useVersion'
|
||||||
|
import { useTranslation } from 'components/hooks/useTranslation'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
variant?: 'inline'
|
variant?: 'inline'
|
||||||
@@ -14,13 +15,14 @@ export const HomepageVersionPicker = ({ variant }: Props) => {
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { currentVersion } = useVersion()
|
const { currentVersion } = useVersion()
|
||||||
const { getDetailsProps } = useDetails({})
|
const { getDetailsProps } = useDetails({})
|
||||||
const { allVersions, page, enterpriseServerVersions } = useMainContext()
|
const { allVersions, page, enterpriseServerVersions, isHomepageVersion } = useMainContext()
|
||||||
|
const { t } = useTranslation('homepage')
|
||||||
|
|
||||||
if (page.permalinks && page.permalinks.length <= 1) {
|
if (page.permalinks && page.permalinks.length <= 1) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = allVersions[currentVersion].versionTitle
|
const label = isHomepageVersion ? t('version_picker') : allVersions[currentVersion].versionTitle
|
||||||
|
|
||||||
if (variant === 'inline') {
|
if (variant === 'inline') {
|
||||||
return (
|
return (
|
||||||
@@ -33,6 +35,9 @@ export const HomepageVersionPicker = ({ variant }: Props) => {
|
|||||||
</summary>
|
</summary>
|
||||||
<div>
|
<div>
|
||||||
{(page.permalinks || []).map((permalink) => {
|
{(page.permalinks || []).map((permalink) => {
|
||||||
|
if (permalink.pageVersion === 'homepage') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
key={permalink.href}
|
key={permalink.href}
|
||||||
@@ -73,6 +78,10 @@ export const HomepageVersionPicker = ({ variant }: Props) => {
|
|||||||
</summary>
|
</summary>
|
||||||
<Dropdown.Menu direction="sw">
|
<Dropdown.Menu direction="sw">
|
||||||
{(page.permalinks || []).map((permalink) => {
|
{(page.permalinks || []).map((permalink) => {
|
||||||
|
if (permalink.pageVersion === 'homepage') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown.Item key={permalink.href}>
|
<Dropdown.Item key={permalink.href}>
|
||||||
<Link href={permalink.href}>{permalink.pageVersionTitle}</Link>
|
<Link href={permalink.href}>{permalink.pageVersionTitle}</Link>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<head>
|
<head>
|
||||||
{% comment %} For human readers {% endcomment %}
|
{% comment %} For human readers {% endcomment %}
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>{% if error == '404' %}{% data ui.errors.oops %}{% elsif page.documentType == 'homepage' and currentVersion == 'free-pro-team@latest' %}GitHub Documentation{% elsif page.fullTitle %}{{ page.fullTitle }}{% else %}GitHub Documentation{% endif %}</title>
|
<title>{% if error == '404' %}{% data ui.errors.oops %}{% elsif currentVersion == 'homepage' %}GitHub Documentation{% elsif page.fullTitle %}{{ page.fullTitle }}{% else %}GitHub Documentation{% endif %}</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="alternate icon" type="image/png" href="/assets/images/site/favicon.png">
|
<link rel="alternate icon" type="image/png" href="/assets/images/site/favicon.png">
|
||||||
<link rel="icon" type="image/svg+xml" href="/assets/images/site/favicon.svg">
|
<link rel="icon" type="image/svg+xml" href="/assets/images/site/favicon.svg">
|
||||||
|
|||||||
@@ -6,17 +6,23 @@
|
|||||||
<details class="dropdown-withArrow position-relative details details-reset mr-md-3 close-when-clicked-outside">
|
<details class="dropdown-withArrow position-relative details details-reset mr-md-3 close-when-clicked-outside">
|
||||||
<summary class="py-2 color-text-primary" role="button" aria-label="Toggle versions list">
|
<summary class="py-2 color-text-primary" role="button" aria-label="Toggle versions list">
|
||||||
<div class="d-flex flex-items-center flex-justify-between">
|
<div class="d-flex flex-items-center flex-justify-between">
|
||||||
|
{% if currentVersion == 'homepage' %}
|
||||||
|
{% data ui.homepage.version_picker %}
|
||||||
|
{% else %}
|
||||||
{{ allVersions[currentVersion].versionTitle }}
|
{{ allVersions[currentVersion].versionTitle }}
|
||||||
|
{% endif %}
|
||||||
<svg class="arrow ml-md-1" width="14px" height="8px" viewBox="0 0 14 8" xml:space="preserve" fill="none" stroke="currentColor"><path d="M1,1l6.2,6L13,1"></path></svg>
|
<svg class="arrow ml-md-1" width="14px" height="8px" viewBox="0 0 14 8" xml:space="preserve" fill="none" stroke="currentColor"><path d="M1,1l6.2,6L13,1"></path></svg>
|
||||||
</div>
|
</div>
|
||||||
</summary>
|
</summary>
|
||||||
<div id="versions-selector" class="position-md-absolute nav-desktop-langDropdown p-md-4 right-md-n4 top-md-6" style="z-index: 6;">
|
<div id="versions-selector" class="position-md-absolute nav-desktop-langDropdown p-md-4 right-md-n4 top-md-6" style="z-index: 6;">
|
||||||
{% for permalink in page.permalinks %}
|
{% for permalink in page.permalinks %}
|
||||||
|
{% unless permalink.pageVersion == 'homepage' %}
|
||||||
<a
|
<a
|
||||||
href="{{ permalink.href }}"
|
href="{{ permalink.href }}"
|
||||||
class="d-block py-2 no-underline {% if currentPath == permalink.href %}active{% else %}Link--primary{% endif %}"
|
class="d-block py-2 no-underline {% if currentPath == permalink.href %}active{% else %}Link--primary{% endif %}"
|
||||||
style="white-space: nowrap"
|
style="white-space: nowrap"
|
||||||
>{{ allVersions[permalink.pageVersion].versionTitle }}</a>
|
>{{ allVersions[permalink.pageVersion].versionTitle }}</a>
|
||||||
|
{% endunless %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% include all-enterprise-releases-link %}
|
{% include all-enterprise-releases-link %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<h2 class="text-mono f5 text-normal color-text-secondary text-md-center mb-4">{% data ui.homepage.explore_by_product %}</h2>
|
<h2 class="text-mono f5 text-normal color-text-secondary text-md-center mb-4">{% data ui.homepage.explore_by_product %}</h2>
|
||||||
<div class="d-flex flex-wrap gutter gutter-xl-spacious">
|
<div class="d-flex flex-wrap gutter gutter-xl-spacious">
|
||||||
{% for product in activeProducts %}
|
{% for product in activeProducts %}
|
||||||
{% if product.versions contains currentVersion %}
|
{% if product.versions contains currentVersion or currentVersion == 'homepage' %}
|
||||||
<div class="d-flex flex-column col-12 col-sm-6 col-lg-3 pb-4">
|
<div class="d-flex flex-column col-12 col-sm-6 col-lg-3 pb-4">
|
||||||
<a class="btn-mktg flex-auto d-flex flex-items-center btn-outline-mktg btn-large-mktg ws-normal " href="{% unless product.external %}/{{ currentLanguage }}{% endunless %}{% if product.versions contains currentVersion %}/{{currentVersion}}/{{product.id}}{% else %}{{product.href}}{% endif %}" {% if product.external %}target="_blank"{% endif %}>{{ product.name }}
|
<a class="btn-mktg flex-auto d-flex flex-items-center btn-outline-mktg btn-large-mktg ws-normal " href="{% unless product.external %}/{{ currentLanguage }}{% endunless %}{% if product.versions contains currentVersion %}/{{currentVersion}}/{{product.id}}{% else %}{{product.href}}{% endif %}" {% if product.external %}target="_blank"{% endif %}>{{ product.name }}
|
||||||
{% if product.external %}
|
{% if product.external %}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ function getVersionStringFromPath (href) {
|
|||||||
|
|
||||||
// Return immediately if this is a link to the homepage
|
// Return immediately if this is a link to the homepage
|
||||||
if (href === '/') {
|
if (href === '/') {
|
||||||
return nonEnterpriseDefaultVersion
|
return 'homepage'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the first segment
|
// Get the first segment
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const assert = require('assert')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const patterns = require('./patterns')
|
const patterns = require('./patterns')
|
||||||
const allVersions = require('./all-versions')
|
const allVersions = require('./all-versions')
|
||||||
|
const nonEnterpriseDefaultVersion = require('./non-enterprise-default-version')
|
||||||
const removeFPTFromPath = require('./remove-fpt-from-path')
|
const removeFPTFromPath = require('./remove-fpt-from-path')
|
||||||
|
|
||||||
class Permalink {
|
class Permalink {
|
||||||
@@ -26,10 +27,24 @@ class Permalink {
|
|||||||
assert(languageCode, 'languageCode is required')
|
assert(languageCode, 'languageCode is required')
|
||||||
|
|
||||||
const permalinks = applicableVersions
|
const permalinks = applicableVersions
|
||||||
|
// skip the Dotcom homepage here because a special homepage permalink is added below
|
||||||
|
.filter(pageVersion => !(pageVersion === nonEnterpriseDefaultVersion && relativePath === 'index.md'))
|
||||||
.map(pageVersion => {
|
.map(pageVersion => {
|
||||||
return new Permalink(languageCode, pageVersion, relativePath, title)
|
return new Permalink(languageCode, pageVersion, relativePath, title)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// special permalink for homepage
|
||||||
|
if (relativePath === 'index.md') {
|
||||||
|
const homepagePermalink = {
|
||||||
|
...permalinks[0],
|
||||||
|
href: '/' + languageCode,
|
||||||
|
pageVersion: 'homepage',
|
||||||
|
pageVersionTitle: permalinks[0].title,
|
||||||
|
homepage: true
|
||||||
|
}
|
||||||
|
permalinks.push(homepagePermalink)
|
||||||
|
}
|
||||||
|
|
||||||
return permalinks
|
return permalinks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ module.exports = async function contextualize (req, res, next) {
|
|||||||
req.context.siteTree = siteTree
|
req.context.siteTree = siteTree
|
||||||
req.context.pages = pageMap
|
req.context.pages = pageMap
|
||||||
|
|
||||||
|
// TODO we should create new data directories for these example files instead of using variable files
|
||||||
|
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
|
// JS + CSS asset paths
|
||||||
req.context.builtAssets = builtAssets
|
req.context.builtAssets = builtAssets
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type LandingPageProps = {
|
|||||||
function LandingPage(props: LandingPageProps) {
|
function LandingPage(props: LandingPageProps) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { gettingStartedLinks, popularLinks } = props
|
const { gettingStartedLinks, popularLinks } = props
|
||||||
const { activeProducts } = useMainContext()
|
const { activeProducts, isHomepageVersion } = useMainContext()
|
||||||
const { currentVersion } = useVersion()
|
const { currentVersion } = useVersion()
|
||||||
const { t } = useTranslation(['homepage', 'search', 'toc'])
|
const { t } = useTranslation(['homepage', 'search', 'toc'])
|
||||||
return (
|
return (
|
||||||
@@ -80,7 +80,7 @@ function LandingPage(props: LandingPageProps) {
|
|||||||
</h2>
|
</h2>
|
||||||
<div className="d-flex flex-wrap gutter gutter-xl-spacious">
|
<div className="d-flex flex-wrap gutter gutter-xl-spacious">
|
||||||
{activeProducts.map((product) => {
|
{activeProducts.map((product) => {
|
||||||
if (!product.versions?.includes(currentVersion) && !product.external) {
|
if (!product.versions?.includes(currentVersion) && !isHomepageVersion) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ describe('Page class', () => {
|
|||||||
basePath: path.join(__dirname, '../../content'),
|
basePath: path.join(__dirname, '../../content'),
|
||||||
languageCode: 'en'
|
languageCode: 'en'
|
||||||
})
|
})
|
||||||
expect(page.permalinks.find(permalink => permalink.pageVersion === nonEnterpriseDefaultVersion).href).toBe('/en')
|
expect(page.permalinks.find(permalink => permalink.pageVersion === 'homepage').href).toBe('/en')
|
||||||
expect(page.permalinks.find(permalink => permalink.pageVersion === `enterprise-server@${enterpriseServerReleases.oldestSupported}`).href).toBe(`/en/enterprise-server@${enterpriseServerReleases.oldestSupported}`)
|
expect(page.permalinks.find(permalink => permalink.pageVersion === `enterprise-server@${enterpriseServerReleases.oldestSupported}`).href).toBe(`/en/enterprise-server@${enterpriseServerReleases.oldestSupported}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const getApplicableVersions = require('../../lib/get-applicable-versions')
|
|||||||
// Permalink.derive requires: languageCode, relativePath, title, versions (<- FM prop)
|
// Permalink.derive requires: languageCode, relativePath, title, versions (<- FM prop)
|
||||||
|
|
||||||
describe('Permalink class', () => {
|
describe('Permalink class', () => {
|
||||||
|
// We can only use Permalink.derive to get the special 'homepage' permalink
|
||||||
test('derives info for unversioned homepage', () => {
|
test('derives info for unversioned homepage', () => {
|
||||||
const versions = {
|
const versions = {
|
||||||
'free-pro-team': '*',
|
'free-pro-team': '*',
|
||||||
@@ -14,7 +15,7 @@ describe('Permalink class', () => {
|
|||||||
}
|
}
|
||||||
const permalinks = Permalink.derive('en', 'index.md', 'Hello World', getApplicableVersions(versions))
|
const permalinks = Permalink.derive('en', 'index.md', 'Hello World', getApplicableVersions(versions))
|
||||||
expect(permalinks.length).toBeGreaterThan(1)
|
expect(permalinks.length).toBeGreaterThan(1)
|
||||||
const homepagePermalink = permalinks.find(permalink => permalink.pageVersion === nonEnterpriseDefaultVersion)
|
const homepagePermalink = permalinks.find(permalink => permalink.pageVersion === 'homepage')
|
||||||
expect(homepagePermalink.href).toBe('/en')
|
expect(homepagePermalink.href).toBe('/en')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ describe('versions middleware', () => {
|
|||||||
|
|
||||||
test('adds res.context.currentVersion string', async () => {
|
test('adds res.context.currentVersion string', async () => {
|
||||||
let currentVersion = await getJSON('/en?json=currentVersion')
|
let currentVersion = await getJSON('/en?json=currentVersion')
|
||||||
expect(currentVersion).toBe(nonEnterpriseDefaultVersion)
|
expect(currentVersion).toBe('homepage')
|
||||||
|
|
||||||
currentVersion = await getJSON(`/en/${nonEnterpriseDefaultVersion}?json=currentVersion`)
|
currentVersion = await getJSON(`/en/${nonEnterpriseDefaultVersion}?json=currentVersion`)
|
||||||
expect(currentVersion).toBe(nonEnterpriseDefaultVersion)
|
expect(currentVersion).toBe('homepage')
|
||||||
|
|
||||||
currentVersion = await getJSON(`/en/enterprise-server@${latest}?json=currentVersion`)
|
currentVersion = await getJSON(`/en/enterprise-server@${latest}?json=currentVersion`)
|
||||||
expect(currentVersion).toBe(`enterprise-server@${latest}`)
|
expect(currentVersion).toBe(`enterprise-server@${latest}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user