Skip to content

Commit

Permalink
Чинит фид
Browse files Browse the repository at this point in the history
  • Loading branch information
igsekor committed Dec 28, 2023
1 parent 10ee320 commit 47ca154
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
36 changes: 22 additions & 14 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,34 +112,42 @@ module.exports = function (config) {
]

let currentYear = 0
const posts = changeLog
.split('\n')
.filter((s) => s.match(/^(-|##) /))
.map((s) => {
const filteredPosts = changeLog.split('\n').filter((s) => s.match(/^(-|##) /))

const posts = await Promise.all(
filteredPosts.map(async (s) => {
if (s.match(/## .+ [0-9]{4}/)) {
currentYear = Number(s.replace(/## .+ /, ''))
return s
} else {
const post = {}

const stringParts = s.replace(/^- /, '').split(', [')
const date = stringParts[0].split(' ')
const currentDay = Number(date[0])
const currentMonth = months.indexOf(date[1])

const post = {}
const titledLink = stringParts[1].split('](')
post['date'] = new Date(Date.parse(`${currentYear}-${currentMonth + 1}-${currentDay}`))
post['date'] = new Date(Date.parse(`${currentYear}-${currentMonth + 1}-${currentDay}`)).toISOString()
post['title'] = titledLink[0].replace(/^\[/, '')
post['url'] = titledLink[1].replace(/\), [А-ЯЁа-яё ,]*/, '')
post['summary'] = collectionApi
.getFilteredByGlob(`src${post['url'].replace('https://doka.guide', '')}*.md`)[0]
?.template.inputContent.split('\n')
.filter((s) => s.match(/^description: /))[0]
.replace(/^description: /, '')
const rawArticle = collectionApi.getFilteredByGlob(
`src${post['url'].replace('https://doka.guide', '')}*.md`,
)[0]
if (rawArticle) {
const articleContent = await rawArticle.template.inputContent
const articleDescription = articleContent
.split('\n')
.filter((s) => s.match(/^description: /))[0]
.replace(/^description: /, '')
post['summary'] = articleDescription
}

return post
}
})
return posts.filter((s) => typeof s === 'object')
}),
)

return posts.filter(async (s) => typeof (await s) !== 'string')
})

config.addCollection('people', (collectionApi) => {
Expand Down
16 changes: 12 additions & 4 deletions src/views/feed.11tydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module.exports = {
eleventyExcludeFromCollections: true,
meta: {
title: 'Новое в Доке',
subtitle:
'Дока — это документация для разработчиков на понятном языке. Её пишет сообщество, чтобы помогать друг другу. Ваши знания и опыт важны. Делитесь ими, мы поможем.',
subtitle: 'Дока — это документация для разработчиков на понятном языке.',
language: 'ru',
url: 'https://doka.guide/',
author: {
Expand All @@ -14,8 +13,17 @@ module.exports = {
},

eleventyComputed: {
summary: function () {
return 'Test'
posts: async function (data) {
const { collections } = data
return collections.posts.filter((p) => typeof p === 'object').sort((p1, p2) => p1.date - p2.date)
},
updated: async function (data) {
const { posts } = data
if (posts[0]) {
return posts[0]?.date
} else {
return new Date().toISOString()
}
},
},
}
16 changes: 9 additions & 7 deletions src/views/feed.njk
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ meta.url }}">
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ meta.url }}/">
<title>{{ meta.title }}</title>
<subtitle>{{ meta.subtitle }}</subtitle>
<link href="{{ permalink | absoluteUrl(meta.url) }}" rel="self"/>
<link href="{{ meta.url }}"/>
<updated>{{ collections.posts | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ meta.url }}</id>
<link href="{{ meta.url }}/"/>
<updated>{{ updated }}</updated>
<id>{{ meta.url }}/</id>
<author>
<name>{{ meta.author.name }}</name>
<email>{{ meta.author.email }}</email>
</author>
{%- for post in collections.posts %}
{%- for post in posts %}
<entry>
<title>{{ post.title }}</title>
<link href="{{ post.url }}"/>
<updated>{{ post.date | dateToRfc3339 }}</updated>
<updated>{{ post.date }}</updated>
<id>{{ post.url }}</id>
<content xml:lang="{{ meta.language }}" type="html">{{ post.summary | htmlToAbsoluteUrls(post.url) }}</content>
{% if post.description %}
<content xml:lang="{{ meta.language }}" type="html">{{ post.description | htmlToAbsoluteUrls(post.url) }}</content>
{% endif %}
</entry>
{%- endfor %}
</feed>

0 comments on commit 47ca154

Please sign in to comment.