@@ -21,7 +21,7 @@ enum ResourceType: String, CustomStringConvertible {
2121 case readingAssignment = " Reading Assignment "
2222 case programmingProject = " Programming Project "
2323
24- static let all : [ ResourceType ] = [ . video, . slides, . demoCode, . readingAssignment, . programmingProject]
24+ static let all : LazyCollection < [ ResourceType ] > = [ . video, . slides, . demoCode, . readingAssignment, . programmingProject] . lazy
2525
2626 var description : String {
2727 switch self {
@@ -44,14 +44,8 @@ struct Resource: CustomStringConvertible {
4444
4545 if rawType. contains ( " video " ) {
4646 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
5549 } else {
5650 fatalError ( " Unknown Raw Type " )
5751 }
@@ -132,19 +126,19 @@ class ParsingDelegate: NSObject, XMLParserDelegate {
132126 }
133127
134128 func parserDidEndDocument( _ parser: XMLParser ) {
135- let sorted = ResourceType . all. map { type in
129+ let sorted = ResourceType . all. map { [ resources ] type in
136130 resources. filter { $0. type == type } . sorted { $0. index < $1. index }
137131 }
138132
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 "
140134 for (index, type) in ResourceType . all. enumerated ( ) {
141135 if sorted [ index] . count > 0 {
142136 out += " # \( type) \n \n "
143137 + " \( sorted [ index] . reduce ( " " ) { " \( $0) \( $1) \n " } ) \n "
144138 }
145139 }
146140
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
148142 let url = URL ( fileURLWithPath: cwd) . deletingLastPathComponent ( ) . appendingPathComponent ( " download.md " )
149143 do {
150144 try out. write ( to: url, atomically: true , encoding: . utf8)
0 commit comments