@@ -28,7 +28,7 @@ VideoUrl:
2828<!---
2929EXAMPLE
3030Name: John Appleseed
31- Status: Submitted <or> Accepted <or> Rejected
31+ Status: Submitted <or> Winner <or> Distinguished <or> Rejected
3232Technologies: SwiftUI, RealityKit, CoreGraphic
3333
3434AboutMeUrl: https://linkedin.com/in/johnappleseed
@@ -56,14 +56,19 @@ for potentialTemplate in potentialTemplates {
5656 let lines = potentialTemplate. content. split ( separator: " \n " )
5757
5858 guard lines. count >= 6 else { continue }
59- guard lines [ 0 ] . hasPrefix ( " Name: " ) && lines [ 0 ] . count > " Name: " . count else { continue }
60- guard lines [ 1 ] . hasPrefix ( " Status: " ) && lines [ 1 ] . count > " Status: " . count else { continue }
61- guard lines [ 2 ] . hasPrefix ( " Technologies: " ) && lines [ 2 ] . count > " Technologies: " . count else { continue }
59+ guard lines [ 0 ] . hasPrefix ( " Name: " ) else { continue }
60+ guard lines [ 1 ] . hasPrefix ( " Status: " ) else { continue }
61+ guard lines [ 2 ] . hasPrefix ( " Technologies: " ) else { continue }
6262 guard lines [ 3 ] . hasPrefix ( " AboutMeUrl: " ) else { continue }
6363 guard lines [ 4 ] . hasPrefix ( " SourceUrl: " ) else { continue }
6464 guard lines [ 5 ] . hasPrefix ( " VideoUrl: " ) else { continue }
6565
66- let newFilename = lines [ 0 ] . replacingOccurrences ( of: " Name: " , with: " " ) . lowercased ( ) . replacingOccurrences ( of: " " , with: " " ) + " .md "
66+ let newFilename = lines [ 0 ]
67+ . replacingOccurrences ( of: " Name: " , with: " " )
68+ . trimmingCharacters ( in: . whitespacesAndNewlines)
69+ . lowercased ( )
70+ . replacingOccurrences ( of: " " , with: " " ) + " .md "
71+
6772 validatedTemplates. append (
6873 (
6974 originalFilename: potentialTemplate. filename,
@@ -109,16 +114,25 @@ struct Submission {
109114 enum Status : String {
110115 case submitted = " Submitted "
111116 case accepted = " Accepted "
117+ case winner = " Winner "
118+ case distinguished = " Distinguished "
112119 case rejected = " Rejected "
120+ case unknown = " Unknown "
113121
114122 var iconURLString : String {
115123 switch self {
116124 case . submitted:
117- " https://img.shields.io/badge/submitted-grey ?style=for-the-badge "
125+ " https://img.shields.io/badge/submitted-slategrey ?style=for-the-badge "
118126 case . accepted:
119127 " https://img.shields.io/badge/accepted-green?style=for-the-badge "
128+ case . winner:
129+ " https://img.shields.io/badge/winner-green?style=for-the-badge "
130+ case . distinguished:
131+ " https://img.shields.io/badge/distinguished-goldenrod?style=for-the-badge "
120132 case . rejected:
121133 " https://img.shields.io/badge/rejected-firebrick?style=for-the-badge "
134+ case . unknown:
135+ " https://img.shields.io/badge/unknown-grey?style=for-the-badge "
122136 }
123137 }
124138 }
@@ -159,6 +173,14 @@ struct Submission {
159173// MARK: - Load all submission files into Submission model
160174let submissionFiles = ( try ? fileManager. contentsOfDirectory ( atPath: submissionsDirectoryName) ) ?? [ ]
161175
176+ func toValue( _ string: String . SubSequence , key: String ) -> String ? {
177+ let value = String ( string)
178+ . replacingOccurrences ( of: key, with: " " )
179+ . trimmingCharacters ( in: . whitespacesAndNewlines)
180+
181+ return value. isEmpty ? nil : value
182+ }
183+
162184var submissions = [ Submission] ( )
163185for submissionFile in submissionFiles {
164186 guard let content = try ? String ( contentsOfFile: " \( submissionsDirectoryName) / \( submissionFile) " , encoding: . utf8) else { continue }
@@ -167,36 +189,36 @@ for submissionFile in submissionFiles {
167189 guard lines. count >= 6 else { continue }
168190
169191 let name : String ? = if lines [ 0 ] . hasPrefix ( " Name: " ) {
170- lines [ 0 ] . replacingOccurrences ( of : " Name: " , with : " " )
192+ toValue ( lines [ 0 ] , key : " Name: " )
171193 } else { nil }
172194
173- let status : Submission . Status ? = if lines [ 1 ] . hasPrefix ( " Status: " ) {
195+ let status : Submission . Status ? = if lines [ 1 ] . hasPrefix ( " Status: " ) , let value = toValue ( lines [ 1 ] , key : " Status: " ) {
174196 . init(
175- rawValue: lines [ 1 ] . replacingOccurrences ( of : " Status: " , with : " " )
197+ rawValue: value
176198 )
177199 } else { nil }
178200
179- let technologies : [ String ] = if lines [ 2 ] . hasPrefix ( " Technologies: " ) {
180- lines [ 2 ] . replacingOccurrences ( of : " Technologies: " , with : " " ) . split ( separator: " , " ) . map { String ( $0) }
201+ let technologies : [ String ] = if lines [ 2 ] . hasPrefix ( " Technologies: " ) , let value = toValue ( lines [ 2 ] , key : " Technologies: " ) {
202+ value . split ( separator: " , " ) . map { String ( $0) }
181203 } else { [ ] }
182204
183- let aboutMeUrl : URL ? = if lines [ 3 ] . hasPrefix ( " AboutMeUrl: " ) {
184- URL ( string: lines [ 3 ] . replacingOccurrences ( of : " AboutMeUrl: " , with : " " ) . replacingOccurrences ( of : " " , with : " " ) )
205+ let aboutMeUrl : URL ? = if lines [ 3 ] . hasPrefix ( " AboutMeUrl: " ) , let value = toValue ( lines [ 3 ] , key : " AboutMeUrl: " ) {
206+ URL ( string: value )
185207 } else { nil }
186208
187- let sourceUrl : URL ? = if lines [ 4 ] . hasPrefix ( " SourceUrl: " ) {
188- URL ( string: lines [ 4 ] . replacingOccurrences ( of : " SourceUrl: " , with : " " ) . replacingOccurrences ( of : " " , with : " " ) )
209+ let sourceUrl : URL ? = if lines [ 4 ] . hasPrefix ( " SourceUrl: " ) , let value = toValue ( lines [ 4 ] , key : " SourceUrl: " ) {
210+ URL ( string: value )
189211 } else { nil }
190212
191- let videoUrl : URL ? = if lines [ 5 ] . hasPrefix ( " VideoUrl: " ) {
192- URL ( string: lines [ 5 ] . replacingOccurrences ( of : " VideoUrl: " , with : " " ) . replacingOccurrences ( of : " " , with : " " ) )
213+ let videoUrl : URL ? = if lines [ 5 ] . hasPrefix ( " VideoUrl: " ) , let value = toValue ( lines [ 5 ] , key : " VideoUrl: " ) {
214+ URL ( string: value )
193215 } else { nil }
194216
195- guard let name, let status else { continue }
217+ guard let name else { continue }
196218 submissions. append (
197219 . init(
198220 name: name,
199- status: status,
221+ status: status ?? . unknown ,
200222 technologies: technologies,
201223 aboutMeUrl: aboutMeUrl,
202224 sourceUrl: sourceUrl,
@@ -205,6 +227,10 @@ for submissionFile in submissionFiles {
205227 )
206228}
207229
230+ //AboutMeUrl
231+ //SourceUrl
232+ //VideoUrl
233+
208234// MARK: - Generate new README.md file from template
209235var readmeFile : String {
210236"""
@@ -218,14 +244,16 @@ List of student submissions for the WWDC \(year) - \(name).
2182442. Fill out the document based on the example in the comment below.
2192453. Make a new Pull Request and wait for the review.
220246
221- ### Submissions
247+ #### How to update your submission?
248+ If you would like to update your submission status please find your file in `Submission` directory. Edit file, update status and create Pull Request.
222249
223- Total: \( submissions. count) \\
224- Accepted: \( submissions. filter { $0. status == . accepted } . count)
250+ ### Submissions
225251
226252| Name | Source | Video | Technologies | Status |
227253|-----:|:------:|:-----------:|:-------------|:------:|
228254\( submissions. sorted ( by: { $0. name < $1. name} ) . map ( \. row) . joined ( separator: " \n " ) )
255+
256+ ##### Total: \( submissions. count) | Accepted: \( submissions. filter { $0. status == . accepted } . count)
229257"""
230258}
231259
0 commit comments