@@ -21,7 +21,7 @@ enum ResourceType: String, CustomStringConvertible {
21
21
case readingAssignment = " Reading Assignment "
22
22
case programmingProject = " Programming Project "
23
23
24
- static let all : [ ResourceType ] = [ . video, . slides, . demoCode, . readingAssignment, . programmingProject]
24
+ static let all : LazyCollection < [ ResourceType ] > = [ . video, . slides, . demoCode, . readingAssignment, . programmingProject] . lazy
25
25
26
26
var description : String {
27
27
switch self {
@@ -44,14 +44,8 @@ struct Resource: CustomStringConvertible {
44
44
45
45
if rawType. contains ( " video " ) {
46
46
type = . video
47
- } else if title. contains ( " Reading Assignment " ) {
48
- type = . readingAssignment
49
- } else if title. contains ( " Programming Project " ) {
50
- type = . programmingProject
51
- } else if title. contains ( " Demo Code " ) {
52
- type = . demoCode
53
- } else if title. contains ( " Slides " ) {
54
- type = . slides
47
+ } else if let resType = ResourceType . all. first ( where: { title. contains ( $0. rawValue) } ) {
48
+ type = resType
55
49
} else {
56
50
fatalError ( " Unknown Raw Type " )
57
51
}
@@ -132,19 +126,19 @@ class ParsingDelegate: NSObject, XMLParserDelegate {
132
126
}
133
127
134
128
func parserDidEndDocument( _ parser: XMLParser ) {
135
- let sorted = ResourceType . all. map { type in
129
+ let sorted = ResourceType . all. map { [ resources ] type in
136
130
resources. filter { $0. type == type } . sorted { $0. index < $1. index }
137
131
}
138
132
139
- var out = " [返回主页](/README.md) | [Back to Main Page](/en/README.md) \n \n "
133
+ var out = " [返回主页](.. /README.md) / [Back to Main Page](.. /en/README.md) \n \n "
140
134
for (index, type) in ResourceType . all. enumerated ( ) {
141
135
if sorted [ index] . count > 0 {
142
136
out += " # \( type) \n \n "
143
137
+ " \( sorted [ index] . reduce ( " " ) { " \( $0) \( $1) \n " } ) \n "
144
138
}
145
139
}
146
140
147
- let cwd = CommandLine . arguments. first { $0. contains ( " main.swift " ) } ?? FileManager . default. currentDirectoryPath
141
+ let cwd = CommandLine . arguments. first { $0. contains ( #file ) } ?? FileManager . default. currentDirectoryPath
148
142
let url = URL ( fileURLWithPath: cwd) . deletingLastPathComponent ( ) . appendingPathComponent ( " download.md " )
149
143
do {
150
144
try out. write ( to: url, atomically: true , encoding: . utf8)
0 commit comments