From e58570e28d800572ad2bc990f752ec5a64032717 Mon Sep 17 00:00:00 2001 From: Grace Park Date: Thu, 22 Jul 2021 08:59:34 -0700 Subject: [PATCH] Part 4: React Cleanup after new 404/500 pages (#20465) * remove 404 and 500 layouts * removing unneeded liquid tags * remove unnecessary includes * remove javascripts * adding liquid tags and update Dockerfile * add tool-switcher --- Dockerfile | 1 - includes/all-enterprise-releases-link.html | 1 - includes/all-products-link.html | 8 - includes/contribution.html | 16 - includes/error-404-deprecation-message.html | 12 - includes/head.html | 33 -- includes/header-notification.html | 69 ---- includes/header-version-switcher.html | 26 -- includes/header.html | 104 ------ .../liquid-tags/homepage-link-with-intro.html | 4 - .../liquid-tags/link-as-article-card.html | 2 +- includes/liquid-tags/link-in-list.html | 2 +- includes/liquid-tags/link-with-intro.html | 2 +- includes/liquid-tags/link.html | 2 +- includes/liquid-tags/topic-link-in-list.html | 2 +- includes/scripts.html | 2 - includes/scroll-button.html | 3 - includes/search-form.html | 10 - includes/sidebar-homepage.html | 19 -- includes/sidebar-product.html | 76 ----- includes/sidebar.html | 22 -- includes/small-footer.html | 22 -- includes/support-section.html | 16 - includes/support.html | 15 - includes/survey.html | 107 ------ includes/toggle-images.html | 4 - includes/tool-switcher.html | 2 +- javascripts/explorer.ts | 16 - javascripts/hyperscript.ts | 46 --- javascripts/index.ts | 8 - javascripts/print.ts | 17 - javascripts/scroll-up.ts | 22 -- javascripts/search-with-your-keyboard.d.ts | 3 - javascripts/search.ts | 307 ------------------ layouts/README.md | 29 -- layouts/error-404.html | 36 -- layouts/error-500.html | 27 -- lib/render-content/index.js | 2 - 38 files changed, 6 insertions(+), 1089 deletions(-) delete mode 100644 includes/all-enterprise-releases-link.html delete mode 100644 includes/all-products-link.html delete mode 100644 includes/contribution.html delete mode 100644 includes/error-404-deprecation-message.html delete mode 100644 includes/head.html delete mode 100644 includes/header-notification.html delete mode 100644 includes/header-version-switcher.html delete mode 100644 includes/header.html delete mode 100644 includes/liquid-tags/homepage-link-with-intro.html delete mode 100644 includes/scripts.html delete mode 100644 includes/scroll-button.html delete mode 100644 includes/search-form.html delete mode 100644 includes/sidebar-homepage.html delete mode 100644 includes/sidebar-product.html delete mode 100644 includes/sidebar.html delete mode 100644 includes/small-footer.html delete mode 100644 includes/support-section.html delete mode 100644 includes/support.html delete mode 100644 includes/survey.html delete mode 100644 includes/toggle-images.html delete mode 100644 javascripts/explorer.ts delete mode 100644 javascripts/hyperscript.ts delete mode 100644 javascripts/print.ts delete mode 100644 javascripts/scroll-up.ts delete mode 100644 javascripts/search-with-your-keyboard.d.ts delete mode 100644 javascripts/search.ts delete mode 100644 layouts/README.md delete mode 100644 layouts/error-404.html delete mode 100644 layouts/error-500.html diff --git a/Dockerfile b/Dockerfile index 0dd8574072..8e107811b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -87,7 +87,6 @@ COPY --chown=node:node assets ./assets COPY --chown=node:node content ./content COPY --chown=node:node data ./data COPY --chown=node:node includes ./includes -COPY --chown=node:node layouts ./layouts COPY --chown=node:node lib ./lib COPY --chown=node:node middleware ./middleware COPY --chown=node:node translations ./translations diff --git a/includes/all-enterprise-releases-link.html b/includes/all-enterprise-releases-link.html deleted file mode 100644 index ed96dfc2d4..0000000000 --- a/includes/all-enterprise-releases-link.html +++ /dev/null @@ -1 +0,0 @@ -See all Enterprise releases diff --git a/includes/all-products-link.html b/includes/all-products-link.html deleted file mode 100644 index 22e691d554..0000000000 --- a/includes/all-products-link.html +++ /dev/null @@ -1,8 +0,0 @@ -{% if currentVersion != 'homepage' %} -
  • - - - All products - -
  • -{% endif %} diff --git a/includes/contribution.html b/includes/contribution.html deleted file mode 100644 index 29652dd0ff..0000000000 --- a/includes/contribution.html +++ /dev/null @@ -1,16 +0,0 @@ -{% unless enterpriseServerReleases.isOldestReleaseDeprecated and currentVersion contains enterpriseServerReleases.oldestSupported %} -
    -

    {% data ui.contribution_cta.title %}

    -

    {% data ui.contribution_cta.body %}

    - {% if page.relativePath %} - {% assign contribution_href = "https://github.com/github/docs/edit/main/content/" | append: page.relativePath %} - {% else %} - {% assign contribution_href = "https://github.com/github/docs" %} - {% endif %} - - {% octicon "git-pull-request" height="16" %} - {% data ui.contribution_cta.button %} - -

    {% data ui.contribution_cta.or %} {% data ui.contribution_cta.to_guidelines %}

    -
    -{% endunless %} diff --git a/includes/error-404-deprecation-message.html b/includes/error-404-deprecation-message.html deleted file mode 100644 index e73938725d..0000000000 --- a/includes/error-404-deprecation-message.html +++ /dev/null @@ -1,12 +0,0 @@ -{% if enterpriseServerReleases.deprecated contains currentVersion %} -{% assign deprecatedDate = enterpriseServerReleases.dates[currentVersion].deprecationDate %} -
    -

    - - {% data reusables.enterprise_deprecation.version_was_deprecated %} - {{ deprecatedDate }}. - - The documentation page you are looking for may have moved. Try going to the GitHub Enterprise Server {{ currentVersion }} documentation homepage or searching by keyword. -

    -
    -{% endif %} diff --git a/includes/head.html b/includes/head.html deleted file mode 100644 index 99425bbd70..0000000000 --- a/includes/head.html +++ /dev/null @@ -1,33 +0,0 @@ - - {% comment %} For human readers {% endcomment %} - - {% 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 %} - - - - - - {% comment %} For Google and Bots {% endcomment %} - {% if page.intro %} - - {% endif %} - {% if page.topics %} - - {% endif %} - {% if page.hidden %} - - {% endif %} - {% for languageVariant in page.languageVariants %} - - {% endfor %} - - - - {% comment %} For our JS {% endcomment %} - - - diff --git a/includes/header-notification.html b/includes/header-notification.html deleted file mode 100644 index 24775efd55..0000000000 --- a/includes/header-notification.html +++ /dev/null @@ -1,69 +0,0 @@ - -{% if currentLanguage != 'en' %} - {% assign translation_notification_type = "true" %} - - - {% if page.relativePath contains '/site-policy/' %} - {% assign translation_notification = site.data.reusables.policies.translation %} - - - {% elsif languages[currentLanguage].wip != true %} - {% assign translation_notification = site.data.ui.header.notices.localization_complete %} - - - {% elsif languages[currentLanguage].wip %} - {% assign translation_notification = site.data.ui.header.notices.localization_in_progress %} - {% endif %} - -{% else %} - - {% if languages[userLanguage].wip == false and userLanguage != 'en' %} - {% assign user_language_redirect_notification_type = true %} - {% endif %} - -{% endif %} - - - - -{% if currentVersion == "github-ae@latest" %} - {% assign release_notification_type = "true" %} - {% assign release_notification = site.data.ui.header.notices.ghae_silent_launch %} - - -{% elsif currentVersion == site.data.variables.release_candidate.version %} - {% assign release_notification_type = "true" %} - {% assign release_notification = allVersions[currentVersion].versionTitle | append: site.data.ui.header.notices.release_candidate %} -{% endif %} - - - -{% if page.hidden and page.relativePath contains "early-access/" %} -{% assign early_access_notification_type = true %} -{% assign early_access_notification = site.data.ui.header.notices.early_access %} -{% endif %} - - -{% if translation_notification_type %} -
    - {{ translation_notification }} -
    -{% endif %} - -{% if user_language_redirect_notification_type %} -
    - This article is also available in your language of choice. Click here -
    -{% endif %} - -{% if release_notification_type %} -
    - {{ release_notification }} -
    -{% endif %} - -{% if early_access_notification_type %} -
    - {{ early_access_notification }} -
    -{% endif %} diff --git a/includes/header-version-switcher.html b/includes/header-version-switcher.html deleted file mode 100644 index 4462c7d344..0000000000 --- a/includes/header-version-switcher.html +++ /dev/null @@ -1,26 +0,0 @@ - -{% if page.relativePath == 'index.md' or page.layout == 'product-landing' or page.layout == 'product-sublanding' or page.layout == 'release-notes' %} -{% if page.permalinks and page.permalinks.length > 1 %} -
    -
    - -
    -{% endif %} -{% endif %} diff --git a/includes/header.html b/includes/header.html deleted file mode 100644 index e4ad00cafd..0000000000 --- a/includes/header.html +++ /dev/null @@ -1,104 +0,0 @@ -
    - {% unless error == '404' %} - {% include header-notification %} - {% endunless %} - -
    - - - -
    -
    - - -
    -
    -
    -
    diff --git a/includes/liquid-tags/homepage-link-with-intro.html b/includes/liquid-tags/homepage-link-with-intro.html deleted file mode 100644 index 3a2ed99940..0000000000 --- a/includes/liquid-tags/homepage-link-with-intro.html +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/includes/liquid-tags/link-as-article-card.html b/includes/liquid-tags/link-as-article-card.html index 23ba93ef90..628a2618ed 100644 --- a/includes/liquid-tags/link-as-article-card.html +++ b/includes/liquid-tags/link-as-article-card.html @@ -11,4 +11,4 @@
    {% endif %} - + \ No newline at end of file diff --git a/includes/liquid-tags/link-in-list.html b/includes/liquid-tags/link-in-list.html index ef9d132a22..51a25c9fe8 100644 --- a/includes/liquid-tags/link-in-list.html +++ b/includes/liquid-tags/link-in-list.html @@ -1 +1 @@ -- {{ title }} +- {{ title }} \ No newline at end of file diff --git a/includes/liquid-tags/link-with-intro.html b/includes/liquid-tags/link-with-intro.html index e5c70bbd8a..361f22042f 100644 --- a/includes/liquid-tags/link-with-intro.html +++ b/includes/liquid-tags/link-with-intro.html @@ -1,4 +1,4 @@ -{% if intro %}{% endif %} +{% if intro %}{% endif %} \ No newline at end of file diff --git a/includes/liquid-tags/link.html b/includes/liquid-tags/link.html index 1d4faae5b2..c41d80ea0e 100644 --- a/includes/liquid-tags/link.html +++ b/includes/liquid-tags/link.html @@ -1 +1 @@ -{{ title }} +{{ title }} \ No newline at end of file diff --git a/includes/liquid-tags/topic-link-in-list.html b/includes/liquid-tags/topic-link-in-list.html index 8870536b3c..87d5ddfdc2 100644 --- a/includes/liquid-tags/topic-link-in-list.html +++ b/includes/liquid-tags/topic-link-in-list.html @@ -1 +1 @@ -- {{ title }} +- {{ title }} \ No newline at end of file diff --git a/includes/scripts.html b/includes/scripts.html deleted file mode 100644 index 6f328a0cc3..0000000000 --- a/includes/scripts.html +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/includes/scroll-button.html b/includes/scroll-button.html deleted file mode 100644 index 772ed5ac89..0000000000 --- a/includes/scroll-button.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/includes/search-form.html b/includes/search-form.html deleted file mode 100644 index 5749ba0803..0000000000 --- a/includes/search-form.html +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/includes/sidebar-homepage.html b/includes/sidebar-homepage.html deleted file mode 100644 index 0dbccee175..0000000000 --- a/includes/sidebar-homepage.html +++ /dev/null @@ -1,19 +0,0 @@ -{% if currentVersion != 'free-pro-team@latest' %} -{% include all-products-link %} -{% endif %} - -{% for product in activeProducts %} -{% if currentVersion == 'free-pro-team@latest' or product.external or product.versions contains currentVersion %} - -{% endif %} -{% endfor %} diff --git a/includes/sidebar-product.html b/includes/sidebar-product.html deleted file mode 100644 index 94c41df035..0000000000 --- a/includes/sidebar-product.html +++ /dev/null @@ -1,76 +0,0 @@ - - -{% include all-products-link %} - -{% unless currentProductTree.page.hidden %} - -{% if currentProductTree.renderedShortTitle %}{% assign productTitle = currentProductTree.renderedShortTitle %}{% else %}{% assign productTitle = currentProductTree.renderedFullTitle %}{% endif %} - - -
  • - -
  • - -{% endunless %} diff --git a/includes/sidebar.html b/includes/sidebar.html deleted file mode 100644 index d4ed2d8f85..0000000000 --- a/includes/sidebar.html +++ /dev/null @@ -1,22 +0,0 @@ - - diff --git a/includes/small-footer.html b/includes/small-footer.html deleted file mode 100644 index 85957b8c6b..0000000000 --- a/includes/small-footer.html +++ /dev/null @@ -1,22 +0,0 @@ - - -{% include scripts %} diff --git a/includes/support-section.html b/includes/support-section.html deleted file mode 100644 index fbb98fa7df..0000000000 --- a/includes/support-section.html +++ /dev/null @@ -1,16 +0,0 @@ -
    -
    -
    - {% include survey %} -
    -
    - {% include contribution %} -
    -
    - {% include support %} -
    -
    - {% include toggle-images %} -
    -
    -
    diff --git a/includes/support.html b/includes/support.html deleted file mode 100644 index 2a78e31634..0000000000 --- a/includes/support.html +++ /dev/null @@ -1,15 +0,0 @@ - -
    -

    - {% data ui.support.still_need_help %} -

    - {% if currentVersion contains 'enterprise' %}{% assign isEnterprise = true %}{% else %}{% assign isEnterprise = false %}{% endif %} - - {% octicon "people" width="16" %} - {% data ui.support.ask_community %} - - - {% octicon "comment-discussion" width="16" %} - {% data ui.support.contact_support %} - -
    diff --git a/includes/survey.html b/includes/survey.html deleted file mode 100644 index 882b015b8c..0000000000 --- a/includes/survey.html +++ /dev/null @@ -1,107 +0,0 @@ -{% unless enterpriseServerReleases.isOldestReleaseDeprecated and currentVersion contains enterpriseServerReleases.oldestSupported %} -
    -

    - {% data ui.survey.able_to_find %} - {% data ui.survey.privacy_policy %} -

    -

    - - - - -

    - - - - - - - -
    -{% endunless %} diff --git a/includes/toggle-images.html b/includes/toggle-images.html deleted file mode 100644 index 79da415c49..0000000000 --- a/includes/toggle-images.html +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/includes/tool-switcher.html b/includes/tool-switcher.html index 5aca48f340..dec63c8214 100644 --- a/includes/tool-switcher.html +++ b/includes/tool-switcher.html @@ -6,4 +6,4 @@ cURL Desktop - + \ No newline at end of file diff --git a/javascripts/explorer.ts b/javascripts/explorer.ts deleted file mode 100644 index 44bfd0ee6d..0000000000 --- a/javascripts/explorer.ts +++ /dev/null @@ -1,16 +0,0 @@ -const explorerUrl = - location.hostname === 'localhost' - ? 'http://localhost:3000' - : 'https://graphql.github.com/explorer' - -// Pass non-search query params to Explorer app via the iFrame -export default function () { - const graphiqlExplorer = document.getElementById('graphiql') as HTMLIFrameElement - const queryString = window.location.search - - if (!(queryString && graphiqlExplorer)) return - - window.onload = () => { - graphiqlExplorer?.contentWindow?.postMessage(queryString, explorerUrl) - } -} diff --git a/javascripts/hyperscript.ts b/javascripts/hyperscript.ts deleted file mode 100644 index ddef7d9c06..0000000000 --- a/javascripts/hyperscript.ts +++ /dev/null @@ -1,46 +0,0 @@ -const xmlns = 'http://www.w3.org/2000/svg' - -const plainObjectConstructor = {}.constructor - -function exists(value: any) { - return value !== null && typeof value !== 'undefined' -} - -function isPlainObject(value: any) { - return value.constructor === plainObjectConstructor -} - -function isString(value: any) { - return typeof value === 'string' -} - -function renderChildren(el: HTMLElement | SVGElement, children: Array) { - for (const child of children) { - if (isPlainObject(child)) { - Object.entries(child) - .filter(([, value]) => exists(value)) - .forEach(([key, value]) => el.setAttribute(key, value as string)) - } else if (Array.isArray(child)) { - renderChildren(el, child) - } else if (isString(child)) { - el.append(document.createTextNode(child)) - } else { - el.append(child) - } - } -} - -export default function h(tagName: string, ...children: Array) { - const el = ['svg', 'path'].includes(tagName) - ? document.createElementNS(xmlns, tagName) - : document.createElement(tagName) - renderChildren(el, children) - return el -} - -export const tags = Object.fromEntries( - ['div', 'form', 'a', 'input', 'button', 'ol', 'li', 'mark'].map((tagName) => [ - tagName, - (...args: Array) => h(tagName, ...args), - ]) -) diff --git a/javascripts/index.ts b/javascripts/index.ts index 95c5e219bb..4d1ca18b83 100644 --- a/javascripts/index.ts +++ b/javascripts/index.ts @@ -2,11 +2,7 @@ import '../stylesheets/index.scss' import displayPlatformSpecificContent from './display-platform-specific-content' import displayToolSpecificContent from './display-tool-specific-content' -import explorer from './explorer' -import scrollUp from './scroll-up' -import search from './search' import wrapCodeTerms from './wrap-code-terms' -import print from './print' import localization from './localization' import experiment from './experiment' import copyCode from './copy-code' @@ -16,11 +12,7 @@ import toggleImages from './toggle-images' document.addEventListener('DOMContentLoaded', async () => { displayPlatformSpecificContent() displayToolSpecificContent() - explorer() - scrollUp() - search() wrapCodeTerms() - print() localization() copyCode() initializeEvents() diff --git a/javascripts/print.ts b/javascripts/print.ts deleted file mode 100644 index 14c8a05494..0000000000 --- a/javascripts/print.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { EventType, sendEvent } from './events' - -export default function () { - const printButtons = document.querySelectorAll('.js-print') - - Array.from(printButtons).forEach((btn) => { - // Open the print dialog when the button is clicked - btn.addEventListener('click', () => { - window.print() - }) - }) - - // Track print events - window.onbeforeprint = function () { - sendEvent({ type: EventType.print }) - } -} diff --git a/javascripts/scroll-up.ts b/javascripts/scroll-up.ts deleted file mode 100644 index e4604e02f8..0000000000 --- a/javascripts/scroll-up.ts +++ /dev/null @@ -1,22 +0,0 @@ -export default function () { - // function to scroll up to page top - const PageTopBtn = document.getElementById('js-scroll-top') - if (!PageTopBtn) return - - PageTopBtn.addEventListener('click', () => { - window.scrollTo({ - top: 0, - behavior: 'smooth', - }) - }) - - // show scroll button only when display is scroll down - window.addEventListener('scroll', function () { - const y = document.documentElement.scrollTop // get the height from page top - if (y < 100) { - PageTopBtn.classList.remove('show') - } else if (y >= 100) { - PageTopBtn.classList.add('show') - } - }) -} diff --git a/javascripts/search-with-your-keyboard.d.ts b/javascripts/search-with-your-keyboard.d.ts deleted file mode 100644 index b33fead8f5..0000000000 --- a/javascripts/search-with-your-keyboard.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'search-with-your-keyboard' { - export default function searchWithYourKeyboard(inputSelector: string, hitsSelector: string): void -} diff --git a/javascripts/search.ts b/javascripts/search.ts deleted file mode 100644 index 5d1a84e45c..0000000000 --- a/javascripts/search.ts +++ /dev/null @@ -1,307 +0,0 @@ -import { tags } from './hyperscript' -import { sendEvent, EventType } from './events' -import searchWithYourKeyboard from 'search-with-your-keyboard' - -let $searchInputContainer: HTMLElement | null | undefined -let $searchResultsContainer: HTMLElement | null | undefined -let $searchOverlay: HTMLElement | null | undefined -let $searchInput: HTMLInputElement | null | undefined - -let isExplorerPage: boolean - -// This is our default placeholder, but it can be localized with a tag -let placeholder = 'Search topics, products...' -let version: string -let language: string - -export default function search() { - // @ts-ignore - if (window.IS_NEXTJS_PAGE) return - - // We don't want to mess with query params intended for the GraphQL Explorer - isExplorerPage = Boolean(document.getElementById('graphiql')) - - // First, only initialize search if the elements are on the page - $searchInputContainer = document.getElementById('search-input-container') - $searchResultsContainer = document.getElementById('search-results-container') - if (!$searchInputContainer || !$searchResultsContainer) return - - // This overlay exists so if you click off the search, it closes - $searchOverlay = document.querySelector('.search-overlay-desktop') as HTMLElement - - // There's an index for every version/language combination - const { languages, versions, nonEnterpriseDefaultVersion } = JSON.parse( - (document.getElementById('expose') as HTMLScriptElement)?.text || '' - ).searchOptions - version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion) - language = deriveLanguageCodeFromPath(languages) - - // Find search placeholder text in a tag, falling back to a default - const $placeholderMeta = document.querySelector( - 'meta[name="site.data.ui.search.placeholder"]' - ) as HTMLMetaElement - if ($placeholderMeta) { - placeholder = $placeholderMeta.content - } - - // Write the search form into its container - $searchInputContainer.append(tmplSearchInput()) - $searchInput = $searchInputContainer.querySelector('input') as HTMLInputElement - - // Prevent 'enter' from refreshing the page - ;($searchInputContainer.querySelector('form') as HTMLFormElement).addEventListener( - 'submit', - (evt) => evt.preventDefault() - ) - - // Search when the user finished typing - $searchInput.addEventListener('keyup', debounce(onSearch)) - - // Adds ability to navigate search results with keyboard (up, down, enter, esc) - searchWithYourKeyboard('#search-input-container input', '.ais-Hits-item') - - // If the user already has a query in the URL, parse it and search away - if (!isExplorerPage) { - parseExistingSearch() - } - - // If not on home page, decide if search panel should be open - toggleSearchDisplay() // must come after parseExistingSearch -} - -// The home page and 404 pages have a standalone search -function hasStandaloneSearch() { - return document.getElementById('landing') || document.querySelector('body.error-404') !== null -} - -function toggleSearchDisplay() { - // Clear/close search, if ESC is clicked - document.addEventListener('keyup', (e) => { - if (e.key === 'Escape') { - closeSearch() - } - }) - - // If not on homepage... - if (hasStandaloneSearch()) return - - // Open panel if input is clicked - $searchInput?.addEventListener('focus', openSearch) - - // Close panel if overlay is clicked - if ($searchOverlay) { - $searchOverlay.addEventListener('click', closeSearch) - } - - // Open panel if page loads with query in the params/input - if ($searchInput?.value) { - openSearch() - } -} - -// On most pages, opens the search panel -function openSearch() { - $searchInput?.classList.add('js-open') - $searchResultsContainer?.classList.add('js-open') - $searchOverlay?.classList.add('js-open') -} - -// Close panel if not on homepage -function closeSearch() { - if (!hasStandaloneSearch()) { - $searchInput?.classList.remove('js-open') - $searchResultsContainer?.classList.remove('js-open') - $searchOverlay?.classList.remove('js-open') - } - - if ($searchInput) $searchInput.value = '' - onSearch() -} - -function deriveLanguageCodeFromPath(languageCodes: Array) { - let languageCode = location.pathname.split('/')[1] - if (!languageCodes.includes(languageCode)) languageCode = 'en' - return languageCode -} - -function deriveVersionFromPath( - allVersions: Record, - nonEnterpriseDefaultVersion: string -) { - // fall back to the non-enterprise default version (FPT currently) on the homepage, 404 page, etc. - const versionStr = location.pathname.split('/')[2] || nonEnterpriseDefaultVersion - return allVersions[versionStr] || allVersions[nonEnterpriseDefaultVersion] -} - -// Wait for the event to stop triggering for X milliseconds before responding -function debounce(fn: Function, delay = 300) { - let timer: number - return (...args: Array) => { - clearTimeout(timer) - timer = window.setTimeout(() => fn.apply(null, args), delay) - } -} - -// When the user finishes typing, update the results -async function onSearch() { - const query = $searchInput?.value || '' - - // Update the URL with the search parameters in the query string - // UNLESS this is the GraphQL Explorer page, where a query in the URL is a GraphQL query - const pushUrl = new URL(location.toString()) - pushUrl.search = query && !isExplorerPage ? new URLSearchParams({ query }).toString() : '' - history.pushState({}, '', pushUrl.toString()) - - // If there's a query, call the endpoint - // Otherwise, there's no results by default - let results = [] - if (query.trim()) { - const endpointUrl = new URL(location.origin) - endpointUrl.pathname = '/search' - endpointUrl.search = new URLSearchParams({ language, version, query }).toString() - - const response = await fetch(endpointUrl.toString(), { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - }) - results = response.ok ? await response.json() : [] - } - - // Either way, update the display - $searchResultsContainer?.querySelectorAll('*').forEach((el) => el.remove()) - $searchResultsContainer?.append(tmplSearchResults(results)) - toggleStandaloneSearch() - - // Analytics tracking - if (query.trim()) { - sendEvent({ - type: EventType.search, - search_query: query, - // search_context - }) - } -} - -// If on homepage, toggle results container if query is present -function toggleStandaloneSearch() { - if (!hasStandaloneSearch()) return - - const query = $searchInput?.value - const queryPresent = Boolean(query && query.length > 0) - const $results = document.querySelector('.ais-Hits') as HTMLElement - - // Primer classNames for showing and hiding the results container - const activeClass = $searchResultsContainer?.getAttribute('data-active-class') - const inactiveClass = $searchResultsContainer?.getAttribute('data-inactive-class') - - if (!activeClass) { - console.error( - 'container is missing required `data-active-class` attribute', - $searchResultsContainer - ) - return - } - - if (!inactiveClass) { - console.error( - 'container is missing required `data-inactive-class` attribute', - $searchResultsContainer - ) - return - } - - // hide the container when no query is present - $searchResultsContainer?.classList.toggle(activeClass, queryPresent) - $searchResultsContainer?.classList.toggle(inactiveClass, !queryPresent) - - if (queryPresent && $results) $results.style.display = 'block' -} - -// If the user shows up with a query in the URL, go ahead and search for it -function parseExistingSearch() { - const params = new URLSearchParams(location.search) - if (!params.has('query')) return - if ($searchInput) $searchInput.value = params.get('query') || '' - onSearch() -} - -/** * Template functions ***/ - -function tmplSearchInput() { - // only autofocus on the homepage, and only if no #hash is present in the URL - const autofocus = (hasStandaloneSearch() && !location.hash.length) || null - const { div, form, input, button } = tags - return div( - { class: 'ais-SearchBox' }, - form( - { role: 'search', class: 'ais-SearchBox-form', novalidate: true }, - input({ - class: 'ais-SearchBox-input', - type: 'search', - placeholder, - autofocus, - autocomplete: 'off', - autocorrect: 'off', - autocapitalize: 'off', - spellcheck: 'false', - maxlength: '512', - }), - button({ - class: 'ais-SearchBox-submit', - type: 'submit', - title: 'Submit the search query.', - hidden: true, - }) - ) - ) -} - -type SearchResult = { - url: string - breadcrumbs: string - heading: string - title: string - content: string -} - -function tmplSearchResults(items: Array) { - const { div, ol, li } = tags - return div( - { class: 'ais-Hits', style: 'display:block' }, - ol( - { class: 'ais-Hits-list' }, - items.map((item) => li({ class: 'ais-Hits-item' }, tmplSearchResult(item))) - ) - ) -} - -function tmplSearchResult({ url, breadcrumbs, heading, title, content }: SearchResult) { - const { div, a } = tags - return div( - { class: 'search-result border-top color-border-secondary py-3 px-2' }, - a( - { href: url, class: 'no-underline' }, - div( - { - class: 'search-result-breadcrumbs d-block color-text-primary opacity-60 text-small pb-1', - }, - // Breadcrumbs in search records don't include the page title - markify(breadcrumbs || '') - ), - div( - { class: 'search-result-title d-block h4-mktg color-text-primary' }, - // Display page title and heading (if present exists) - markify(heading ? `${title}: ${heading}` : title) - ), - div({ class: 'search-result-content d-block color-text-secondary' }, markify(content)) - ) - ) -} - -// Convert mark tags in search responses -function markify(text: string) { - const { mark } = tags - return text.split(/<\/?mark>/g).map((el, i) => (i % 2 ? mark(el) : el)) -} diff --git a/layouts/README.md b/layouts/README.md deleted file mode 100644 index 0d25697508..0000000000 --- a/layouts/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Layouts - -The files in this directory are layouts which can be wrapped around pages. - -See also [includes](includes), which are snippets of HTML or Markdown that -can be reused in multiple layouts. - -## Using Layouts - -Be default, `layouts/default.html` will be used for all pages. - -To use a custom layout, add a `layout` value to the page's frontmatter: - -``` ---- -title: Hello World -layout: some-layout ---- -``` - -The example above will use the `layouts/some-layout.html` layout. - -To render a page with no layout, set `layout: false`. - -## Writing Layouts - -Layout files should have a `.html` or `.md` extension, and they -must include the string `{{ content}}` to specify where inner content should -be injected. diff --git a/layouts/error-404.html b/layouts/error-404.html deleted file mode 100644 index 5d6965ac41..0000000000 --- a/layouts/error-404.html +++ /dev/null @@ -1,36 +0,0 @@ - -{% assign error = '404' %} - - {% include head %} - - - {% include sidebar %} - -
    - {% include header %} - -
    -
    - {% include error-404-deprecation-message %} - -

    {% data ui.errors.oops %}

    - -
    - {% data ui.errors.page_doesnt_exist %} -
    - -
    -

    {% data ui.search.need_help %}

    - {% include search-form %} -
    -
    -
    -
    - - - {% include support-section %} - {% include small-footer %} - {% include scroll-button %} -
    - - diff --git a/layouts/error-500.html b/layouts/error-500.html deleted file mode 100644 index b1d928b9fe..0000000000 --- a/layouts/error-500.html +++ /dev/null @@ -1,27 +0,0 @@ - - - {% include head %} - - {% include header %} - -
    -
    -

    {% data ui.errors.oops %}

    - -
    - {% data ui.errors.something_went_wrong %} - {% data ui.errors.we_track_errors %} -
    - - {% if error %} -
    {{ error.stack }}
    - {% endif %} -
    -
    - - - {% include support-section %} - {% include small-footer %} - {% include scroll-button %} - - diff --git a/lib/render-content/index.js b/lib/render-content/index.js index 93b47836ad..84194938be 100644 --- a/lib/render-content/index.js +++ b/lib/render-content/index.js @@ -3,7 +3,6 @@ import renderContent from './renderContent.js' import { ExtendedMarkdown, tags } from '../liquid-tags/extended-markdown.js' import xLink from '../liquid-tags/link.js' import xLinkWithIntro from '../liquid-tags/link-with-intro.js' -import xHomepageLinkWithIntro from '../liquid-tags/homepage-link-with-intro.js' import xLinkInList from '../liquid-tags/link-in-list.js' import xTopicLinkInList from '../liquid-tags/topic-link-in-list.js' import xIndentedDataReference from '../liquid-tags/indented-data-reference.js' @@ -15,7 +14,6 @@ import xIfversion from '../liquid-tags/ifversion.js' // Include custom tags like {% link_with_intro /article/foo %} renderContent.liquid.registerTag('link', xLink('link')) renderContent.liquid.registerTag('link_with_intro', xLinkWithIntro) -renderContent.liquid.registerTag('homepage_link_with_intro', xHomepageLinkWithIntro) renderContent.liquid.registerTag('link_in_list', xLinkInList) renderContent.liquid.registerTag('topic_link_in_list', xTopicLinkInList) renderContent.liquid.registerTag('indented_data_reference', xIndentedDataReference)