Skip to content

Commit

Permalink
✨ Grab emoji in processChangelog()
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jun 26, 2024
1 parent cd086b3 commit 7d08e89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 4 additions & 7 deletions Loop/Updater/UpdateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,11 @@ struct ChangelogSectionView: View {
ForEach($item.body, id: \.id) { line in
let note = line.wrappedValue

let emoji = note.text.prefix(1)
let text = note.text
.suffix(note.text.count - 1)
.trimmingCharacters(in: .whitespacesAndNewlines)

HStack(spacing: 8) {
Text(emoji)
Text(LocalizedStringKey(text))
Text(note.emoji)
Text(LocalizedStringKey(note.text))
.lineSpacing(1.1)

Spacer(minLength: 0)

HStack(spacing: 0) {
Expand All @@ -241,6 +237,7 @@ struct ChangelogSectionView: View {
}
.foregroundStyle(.secondary)
.buttonStyle(.plain)
.fixedSize()
}
.padding(.horizontal, 8)
.padding(.vertical, 4)
Expand Down
10 changes: 8 additions & 2 deletions Loop/Updater/Updater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Updater: ObservableObject {
struct ChangelogNote: Identifiable {
var id: UUID = .init()

var emoji: String
var text: String
var user: String?
var reference: Int?
Expand Down Expand Up @@ -166,7 +167,10 @@ class Updater: ObservableObject {
else {
continue
}

let line = String(line)
.replacingOccurrences(of: "- ", with: "") // Remove bullet point
.trimmingCharacters(in: .whitespaces)

var user: String?
if let regex = try? NSRegularExpression(pattern: #"\(@(.*)\)"#),
Expand All @@ -180,13 +184,15 @@ class Updater: ObservableObject {
reference = Int(Range(match.range(at: 1), in: line).flatMap { String(line[$0]) } ?? "")
}

let emoji = String(line.prefix(1))

let text = line
.replacingOccurrences(of: "- ", with: "") // Remove bullet point
.suffix(line.count - 1)
.replacingOccurrences(of: #"#\d+ "#, with: "", options: .regularExpression) // Remove issue number
.replacingOccurrences(of: #"\(@.*\)"#, with: "", options: .regularExpression) // Remove author
.trimmingCharacters(in: .whitespacesAndNewlines)

changelog[index].body.append(.init(text: text, user: user, reference: reference))
changelog[index].body.append(.init(emoji: emoji, text: text, user: user, reference: reference))
}
}
}
Expand Down

0 comments on commit 7d08e89

Please sign in to comment.