Skip to content

Commit c848c71

Browse files
authored
update: date format & serial number to links
1 parent 868f91b commit c848c71

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

Sources/ArchiveDetective/ReadmeUpdater.swift

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,55 @@ enum ReadmeUpdater {
88
let content = try String(contentsOfFile: readmePath, encoding: .utf8)
99

1010
guard let markerRange = content.range(of: marker) else {
11-
print("Marker not found in README."); fflush(stdout)
11+
print("Marker not found in README.")
1212
return
1313
}
1414

15-
// Build table content
1615
var tableLines = [
17-
"| Repository URL | Status |",
18-
"|----------------|--------|"
16+
"| # | Repository URL | Status |",
17+
"|---|----------------|--------|"
1918
]
2019

21-
let filteredResults = results.filter { $0.status != nil }
20+
let filteredResults = results.enumerated().filter { $0.element.status != nil }
2221

23-
for result in filteredResults {
24-
tableLines.append("| \(result.url) | \(result.status!) |")
22+
for (index, result) in filteredResults {
23+
let status = result.status!.trimmingCharacters(in: .whitespacesAndNewlines)
24+
tableLines.append("| \(index + 1) | \(result.url) | \(status) |")
2525
}
2626

27-
// Timestamps
2827
let now = formattedDate()
29-
let lastUpdated: String
30-
if filteredResults.isEmpty {
31-
lastUpdated = extractPreviousUpdatedDate(from: content) ?? now
32-
} else {
33-
lastUpdated = now
34-
}
28+
let lastUpdated: String = filteredResults.isEmpty
29+
? extractPreviousUpdatedDate(from: content) ?? now
30+
: now
3531

3632
tableLines.append("") // blank line before timestamps
3733
tableLines.append("*Last updated: \(lastUpdated)*")
3834
tableLines.append("*Last checked: \(now)*")
3935

40-
// Inject new section
4136
let newSection = "\(marker)\n\n" + tableLines.joined(separator: "\n")
4237
let updatedContent = content[..<markerRange.lowerBound] + newSection
4338

4439
try updatedContent.write(toFile: readmePath, atomically: true, encoding: .utf8)
45-
print("README.md updated."); fflush(stdout)
4640
}
4741

4842
private static func formattedDate() -> String {
4943
let formatter = DateFormatter()
50-
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss 'UTC'"
44+
formatter.locale = Locale(identifier: "en_US_POSIX")
5145
formatter.timeZone = TimeZone(abbreviation: "UTC")
46+
formatter.dateFormat = "MMMM d, yyyy 'at' h:mm a (z)"
5247
return formatter.string(from: Date())
5348
}
5449

5550
private static func extractPreviousUpdatedDate(from content: String) -> String? {
5651
let pattern = #"\*Last updated: (.*?)\*"#
57-
if let match = content.range(of: pattern, options: .regularExpression) {
58-
let line = String(content[match])
59-
return line
60-
.replacingOccurrences(of: "*Last updated: ", with: "")
61-
.replacingOccurrences(of: "*", with: "")
62-
.trimmingCharacters(in: .whitespacesAndNewlines)
52+
guard let match = content.range(of: pattern, options: .regularExpression) else {
53+
return nil
6354
}
64-
return nil
55+
56+
let line = String(content[match])
57+
return line
58+
.replacingOccurrences(of: "*Last updated: ", with: "")
59+
.replacingOccurrences(of: "*", with: "")
60+
.trimmingCharacters(in: .whitespacesAndNewlines)
6561
}
6662
}

0 commit comments

Comments
 (0)