Skip to content

Commit 47ca154

Browse files
committed
Чинит фид
1 parent 10ee320 commit 47ca154

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

.eleventy.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,42 @@ module.exports = function (config) {
112112
]
113113

114114
let currentYear = 0
115-
const posts = changeLog
116-
.split('\n')
117-
.filter((s) => s.match(/^(-|##) /))
118-
.map((s) => {
115+
const filteredPosts = changeLog.split('\n').filter((s) => s.match(/^(-|##) /))
116+
117+
const posts = await Promise.all(
118+
filteredPosts.map(async (s) => {
119119
if (s.match(/## .+ [0-9]{4}/)) {
120120
currentYear = Number(s.replace(/## .+ /, ''))
121121
return s
122122
} else {
123+
const post = {}
124+
123125
const stringParts = s.replace(/^- /, '').split(', [')
124126
const date = stringParts[0].split(' ')
125127
const currentDay = Number(date[0])
126128
const currentMonth = months.indexOf(date[1])
127-
128-
const post = {}
129129
const titledLink = stringParts[1].split('](')
130-
post['date'] = new Date(Date.parse(`${currentYear}-${currentMonth + 1}-${currentDay}`))
130+
post['date'] = new Date(Date.parse(`${currentYear}-${currentMonth + 1}-${currentDay}`)).toISOString()
131131
post['title'] = titledLink[0].replace(/^\[/, '')
132132
post['url'] = titledLink[1].replace(/\), [А-ЯЁа-яё ,]*/, '')
133-
post['summary'] = collectionApi
134-
.getFilteredByGlob(`src${post['url'].replace('https://doka.guide', '')}*.md`)[0]
135-
?.template.inputContent.split('\n')
136-
.filter((s) => s.match(/^description: /))[0]
137-
.replace(/^description: /, '')
133+
const rawArticle = collectionApi.getFilteredByGlob(
134+
`src${post['url'].replace('https://doka.guide', '')}*.md`,
135+
)[0]
136+
if (rawArticle) {
137+
const articleContent = await rawArticle.template.inputContent
138+
const articleDescription = articleContent
139+
.split('\n')
140+
.filter((s) => s.match(/^description: /))[0]
141+
.replace(/^description: /, '')
142+
post['summary'] = articleDescription
143+
}
138144

139145
return post
140146
}
141-
})
142-
return posts.filter((s) => typeof s === 'object')
147+
}),
148+
)
149+
150+
return posts.filter(async (s) => typeof (await s) !== 'string')
143151
})
144152

145153
config.addCollection('people', (collectionApi) => {

src/views/feed.11tydata.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ module.exports = {
33
eleventyExcludeFromCollections: true,
44
meta: {
55
title: 'Новое в Доке',
6-
subtitle:
7-
'Дока — это документация для разработчиков на понятном языке. Её пишет сообщество, чтобы помогать друг другу. Ваши знания и опыт важны. Делитесь ими, мы поможем.',
6+
subtitle: 'Дока — это документация для разработчиков на понятном языке.',
87
language: 'ru',
98
url: 'https://doka.guide/',
109
author: {
@@ -14,8 +13,17 @@ module.exports = {
1413
},
1514

1615
eleventyComputed: {
17-
summary: function () {
18-
return 'Test'
16+
posts: async function (data) {
17+
const { collections } = data
18+
return collections.posts.filter((p) => typeof p === 'object').sort((p1, p2) => p1.date - p2.date)
19+
},
20+
updated: async function (data) {
21+
const { posts } = data
22+
if (posts[0]) {
23+
return posts[0]?.date
24+
} else {
25+
return new Date().toISOString()
26+
}
1927
},
2028
},
2129
}

src/views/feed.njk

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ meta.url }}">
2+
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="{{ meta.url }}/">
33
<title>{{ meta.title }}</title>
44
<subtitle>{{ meta.subtitle }}</subtitle>
55
<link href="{{ permalink | absoluteUrl(meta.url) }}" rel="self"/>
6-
<link href="{{ meta.url }}"/>
7-
<updated>{{ collections.posts | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
8-
<id>{{ meta.url }}</id>
6+
<link href="{{ meta.url }}/"/>
7+
<updated>{{ updated }}</updated>
8+
<id>{{ meta.url }}/</id>
99
<author>
1010
<name>{{ meta.author.name }}</name>
1111
<email>{{ meta.author.email }}</email>
1212
</author>
13-
{%- for post in collections.posts %}
13+
{%- for post in posts %}
1414
<entry>
1515
<title>{{ post.title }}</title>
1616
<link href="{{ post.url }}"/>
17-
<updated>{{ post.date | dateToRfc3339 }}</updated>
17+
<updated>{{ post.date }}</updated>
1818
<id>{{ post.url }}</id>
19-
<content xml:lang="{{ meta.language }}" type="html">{{ post.summary | htmlToAbsoluteUrls(post.url) }}</content>
19+
{% if post.description %}
20+
<content xml:lang="{{ meta.language }}" type="html">{{ post.description | htmlToAbsoluteUrls(post.url) }}</content>
21+
{% endif %}
2022
</entry>
2123
{%- endfor %}
2224
</feed>

0 commit comments

Comments
 (0)