Skip to content

Commit

Permalink
feat: add sitemap generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Nastya committed Aug 3, 2021
1 parent a83b324 commit 78651ce
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
11 changes: 6 additions & 5 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const { isDev } = require('./pages/views/_data/env')
const { isDev } = require('./pages/views/_data/env');

module.exports = config => {
config.addPassthroughCopy({
'pages/static/assets': 'assets',
'pages/static/tools': '.',
});

config.addFilter("sortByName", (values) => {
config.addFilter('sortByName', (values) => {
if (!values || !Array.isArray(values)) {
console.error(`Unexpected values in "sortByName" filter: ${values}`);
console.error(`Unexpected values in 'sortByName' filter: ${values}`);
return values;
}
return [...values].sort((a, b) => a.data.name.localeCompare(b.data.name))
});


config.setBrowserSyncConfig({
files: [
'pages/dist/bundles/*.js',
Expand All @@ -27,12 +28,12 @@ module.exports = config => {
dir: {
input: 'pages/views',
output: 'pages/dist',
layouts: "_layouts",
layouts: '_layouts',
},
dataTemplateEngine: 'njk',
htmlTemplateEngine: 'njk',
passthroughFileCopy: true,
templateFormats: ['md', 'njk'],
pathPrefix: "/esl/",
pathPrefix: '/esl/',
};
};
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pages/views/404.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: basic
title: 😯 404 😯
containerCls: container
permalink: 404.html
ignore: true
---

<h2 class="text-center text-warning">Page not found </h2>
4 changes: 4 additions & 0 deletions pages/views/_data/site.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Exadel Smart Library",
"url": "https://exadel-inc.github.io/esl"
}
8 changes: 8 additions & 0 deletions pages/views/robots.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
permalink: "/robots.txt"
eleventyExcludeFromCollections: true
---
User-agent: *
Allow: /

Sitemap: {{ site.url }}/sitemap.xml
16 changes: 16 additions & 0 deletions pages/views/sitemap.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
permalink: "/sitemap.xml"
eleventyExcludeFromCollections: true
---

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in collections.all %}
{% if page.data.ignore != true %}
<url>
<loc>{{ site.url }}{{ page.url.replace(r/\/$/, ".html") if page.data.tags else page.url }}</loc>
<lastmod>{{ page.date.toISOString() }}</lastmod>
</url>
{% endif %}
{% endfor %}
<urlset>

0 comments on commit 78651ce

Please sign in to comment.