Skip to content

Commit

Permalink
Fixed duplicate entries in fonts.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ZerGo0 committed Sep 25, 2024
1 parent ebf3466 commit 5988a2b
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions pkg/services/fontsource/fontsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ func downloadFont(ctx context.Context, logger *slog.Logger, outputDir, formats,
Type: font.Type,
}
} else {
sucessfullyDownloadedFont.Subsets = append(sucessfullyDownloadedFont.Subsets, subset)
sucessfullyDownloadedFont.Weights = append(sucessfullyDownloadedFont.Weights, weight)
sucessfullyDownloadedFont.Styles = append(sucessfullyDownloadedFont.Styles, style)
addSubsetIfNotPresent(&sucessfullyDownloadedFont, subset)

addWeightIfNotPresent(&sucessfullyDownloadedFont, weight)

addStyleIfNotPresent(&sucessfullyDownloadedFont, style)
}
}
}
Expand All @@ -209,3 +211,45 @@ func downloadFont(ctx context.Context, logger *slog.Logger, outputDir, formats,

return sucessfullyDownloadedFont
}

func addSubsetIfNotPresent(sucessfullyDownloadedFont *Font, subset string) {
foundSubset := false
for i := range sucessfullyDownloadedFont.Subsets {
if sucessfullyDownloadedFont.Subsets[i] == subset {
foundSubset = true
break
}
}

if !foundSubset {
sucessfullyDownloadedFont.Subsets = append(sucessfullyDownloadedFont.Subsets, subset)
}
}

func addWeightIfNotPresent(sucessfullyDownloadedFont *Font, weight int) {
foundWeight := false
for i := range sucessfullyDownloadedFont.Weights {
if sucessfullyDownloadedFont.Weights[i] == weight {
foundWeight = true
break
}
}

if !foundWeight {
sucessfullyDownloadedFont.Weights = append(sucessfullyDownloadedFont.Weights, weight)
}
}

func addStyleIfNotPresent(sucessfullyDownloadedFont *Font, style string) {
foundStyle := false
for i := range sucessfullyDownloadedFont.Styles {
if sucessfullyDownloadedFont.Styles[i] == style {
foundStyle = true
break
}
}

if !foundStyle {
sucessfullyDownloadedFont.Styles = append(sucessfullyDownloadedFont.Styles, style)
}
}

0 comments on commit 5988a2b

Please sign in to comment.