Skip to content

Commit

Permalink
chore: avoid generating subdirectories for each page on new docs site
Browse files Browse the repository at this point in the history
Refs #15844
  • Loading branch information
mdjermanovic committed Jun 5, 2022
1 parent f31216a commit ff722ab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
19 changes: 18 additions & 1 deletion docs/.eleventy.js
Expand Up @@ -22,7 +22,7 @@ module.exports = function(eleventyConfig) {
* The path prefix is turned off for deploy previews so we can properly
* see changes before deployed.
*/
const pathPrefix = process.env.CONTEXT === "deploy-preview" ? "" : "/docs";
const pathPrefix = process.env.CONTEXT === "production" ? "/docs" : "";

//------------------------------------------------------------------------------
// Filters
Expand Down Expand Up @@ -91,6 +91,23 @@ module.exports = function(eleventyConfig) {
return markdown.render(value);
});

eleventyConfig.addFilter("prettyURL", url => {
if (url.endsWith(".html")) {
return url.slice(0, -".html".length);
}

return url;
});

eleventyConfig.setBrowserSyncConfig({
server: {
baseDir: "_site",
serveStaticOptions: {
extensions: ["html"]
}
}
});

//------------------------------------------------------------------------------
// Plugins
//------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/src/_includes/components/docs-index.html
@@ -1,7 +1,7 @@
{% set navPages = collections.docs | eleventyNavigation %}
{% macro renderNavListItem(entry) -%}
<li class="docs-index__item" {% if entry.children.length %}data-has-children {% endif %}>
<a href="{{ entry.url | url }}" {% if entry.url == page.url %} aria-current="true" {% endif %}>{{ entry.title }}</a>
<a href="{{ entry.url | url | prettyURL }}" {% if entry.url == page.url %} aria-current="true" {% endif %}>{{ entry.title }}</a>
{%- if entry.children.length -%}
<ul data-child-list>
{%- for child in entry.children %}{{ renderNavListItem(child) }}{% endfor -%}
Expand Down
4 changes: 2 additions & 2 deletions docs/src/_includes/layouts/base.njk
Expand Up @@ -9,7 +9,7 @@
<!-- SEO -->
<title>{{ title }}</title>
<meta name="description" content="{{ desc }}">
<!--<link rel="canonical" href="https://docs.eslint.org{{ page.url | url }}">-->
<!--<link rel="canonical" href="https://docs.eslint.org{{ page.url | url | prettyURL }}">-->

<!-- favicon -->
<link rel="icon" href="/favicon.ico" sizes="any"><!-- 32×32 -->
Expand All @@ -25,7 +25,7 @@
<meta property="og:image:alt" content="{{ coverAlt }}">
<meta property="og:locale" content="en_US">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ metadata.url }}{{ page.url }}">
<meta property="og:url" content="{{ metadata.url }}{{ page.url | url | prettyURL }}">
<!-- Twitter -->
<meta name="twitter:title" content="{{ title }}">
<meta name="twitter:card" content="summary_large_image">
Expand Down
3 changes: 3 additions & 0 deletions docs/src/src.json
@@ -0,0 +1,3 @@
{
"permalink": "{{ page.filePathStem }}.html"
}
2 changes: 1 addition & 1 deletion docs/src/static/sitemap.njk
Expand Up @@ -6,7 +6,7 @@ eleventyExcludeFromCollections: true
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in collections.all %}
<url>
<loc>{{ site.url }}{{ page.url | url }}</loc>
<loc>{{ site.url }}{{ page.url | url | prettyURL }}</loc>
<lastmod>{{ page.date.toISOString() }}</lastmod>
<changefreq>{{ page.data.changeFreq or &quot;monthly&quot; }}</changefreq>
</url>
Expand Down

0 comments on commit ff722ab

Please sign in to comment.