@@ -25,27 +25,8 @@ export function rss(channel, data) {
25
25
const now = new Date ( )
26
26
/** @type {Channel } */
27
27
const meta = channel || { title : null , url : null }
28
- /** @type {Array.<Element> } */
29
- const items = [ ]
30
- let index = - 1
31
- /** @type {boolean } */
28
+ /** @type {boolean|undefined } */
32
29
let atom
33
- /** @type {number } */
34
- let offset
35
- /** @type {Array.<Element> } */
36
- let children
37
- /** @type {Entry } */
38
- let datum
39
- /** @type {string } */
40
- let lang
41
- /** @type {string } */
42
- let copy
43
- /** @type {string } */
44
- let url
45
- /** @type {Author } */
46
- let author
47
- /** @type {Enclosure } */
48
- let enclosure
49
30
50
31
if ( meta . title === undefined || meta . title === null ) {
51
32
throw new Error ( 'Expected `channel.title` to be set' )
@@ -55,14 +36,14 @@ export function rss(channel, data) {
55
36
throw new Error ( 'Expected `channel.url` to be set' )
56
37
}
57
38
58
- items . push (
39
+ const items = [
59
40
x ( 'title' , String ( meta . title ) ) ,
60
41
x ( 'description' , String ( meta . description || '' ) || null ) ,
61
42
x ( 'link' , new URL ( meta . url ) . href ) ,
62
- // @ts -ignore `toGTMString` is exactly what we need.
43
+ // @ts -expect-error `toGTMString` is exactly what we need.
63
44
x ( 'lastBuildDate' , now . toGMTString ( ) ) ,
64
45
x ( 'dc:date' , now . toISOString ( ) )
65
- )
46
+ ]
66
47
67
48
if ( meta . feedUrl ) {
68
49
atom = true
@@ -76,26 +57,28 @@ export function rss(channel, data) {
76
57
}
77
58
78
59
if ( meta . lang ) {
79
- lang = normalize ( meta . lang )
60
+ const lang = normalize ( meta . lang )
80
61
items . push ( x ( 'language' , lang ) , x ( 'dc:language' , lang ) )
81
62
}
82
63
83
64
if ( meta . author ) {
84
- copy = '© ' + now . getUTCFullYear ( ) + ' ' + meta . author
65
+ const copy = '© ' + now . getUTCFullYear ( ) + ' ' + meta . author
85
66
items . push ( x ( 'copyright' , copy ) , x ( 'dc:rights' , copy ) )
86
67
}
87
68
88
69
if ( meta . tags ) {
89
- offset = - 1
90
- while ( ++ offset < meta . tags . length ) {
91
- items . push ( x ( 'category' , String ( meta . tags [ offset ] ) ) )
70
+ let index = - 1
71
+ while ( ++ index < meta . tags . length ) {
72
+ items . push ( x ( 'category' , String ( meta . tags [ index ] ) ) )
92
73
}
93
74
}
94
75
95
76
if ( data ) {
77
+ let index = - 1
96
78
while ( ++ index < data . length ) {
97
- datum = data [ index ]
98
- children = [ ]
79
+ const datum = data [ index ]
80
+ /** @type {Array.<Element> } */
81
+ const children = [ ]
99
82
100
83
if ( ! datum . title && ! datum . description && ! datum . descriptionHtml ) {
101
84
throw new Error (
@@ -108,7 +91,7 @@ export function rss(channel, data) {
108
91
if ( datum . title ) children . push ( x ( 'title' , String ( datum . title ) ) )
109
92
110
93
if ( datum . author ) {
111
- author = toAuthor ( datum . author )
94
+ const author = toAuthor ( datum . author )
112
95
children . push ( x ( 'dc:creator' , author . name ) )
113
96
114
97
if ( author . email ) {
@@ -117,7 +100,7 @@ export function rss(channel, data) {
117
100
}
118
101
119
102
if ( datum . url ) {
120
- url = new URL ( datum . url ) . href
103
+ const url = new URL ( datum . url ) . href
121
104
children . push (
122
105
x ( 'link' , url ) ,
123
106
// Do not treat it as a URL, just an opaque identifier.
@@ -130,7 +113,7 @@ export function rss(channel, data) {
130
113
131
114
if ( datum . published !== undefined && datum . published !== null ) {
132
115
children . push (
133
- // @ts -ignore `toGTMString` is exactly what we need.
116
+ // @ts -expect-error `toGTMString` is exactly what we need.
134
117
x ( 'pubDate' , toDate ( datum . published ) . toGMTString ( ) ) ,
135
118
x ( 'dc:date' , toDate ( datum . published ) . toISOString ( ) )
136
119
)
@@ -141,13 +124,14 @@ export function rss(channel, data) {
141
124
}
142
125
143
126
if ( datum . tags ) {
144
- offset = - 1
127
+ let offset = - 1
145
128
while ( ++ offset < datum . tags . length ) {
146
129
children . push ( x ( 'category' , String ( datum . tags [ offset ] ) ) )
147
130
}
148
131
}
149
132
150
- enclosure = datum . enclosure
133
+ const enclosure = datum . enclosure
134
+
151
135
if ( enclosure ) {
152
136
if ( ! enclosure . url ) {
153
137
throw new Error (
0 commit comments