Skip to content

Commit

Permalink
ProcessGDocsDoc: Simplify with goto
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed May 21, 2024
1 parent dc01120 commit ca938ed
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions pkg/almanack/service-gdocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,16 @@ func (svc Services) ProcessGDocsDoc(ctx context.Context, dbDoc db.GDocsDoc) (err
"Embed #%d contains unusual characters.", n,
))
}
embeds = append(embeds, embed)
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)
n++
goto append

case "spl", "spl-embed":
embedHTML := xhtml.InnerText(rows.At(1, 0))
embed.Type = db.SpotlightRawEmbedOrTextTag
embed.Value = embedHTML
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)

case "spl-text":
embed.Type = db.SpotlightRawEmbedOrTextTag
n := xhtml.Clone(rows.At(1, 0))
Expand All @@ -162,15 +160,13 @@ func (svc Services) ProcessGDocsDoc(ctx context.Context, dbDoc db.GDocsDoc) (err
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)

case "partner-embed":
embedHTML := xhtml.InnerText(rows.At(1, 0))
embed.Type = db.PartnerRawEmbedTag
embed.Value = embedHTML
embeds = append(embeds, embed)
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)
n++
goto append

case "partner-text":
embed.Type = db.PartnerTextTag
n := xhtml.Clone(rows.At(1, 0))
Expand All @@ -181,6 +177,7 @@ func (svc Services) ProcessGDocsDoc(ctx context.Context, dbDoc db.GDocsDoc) (err
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)

case "photo", "image", "photograph", "illustration", "illo":
embed.Type = db.ImageEmbedTag
if imageEmbed, warning := svc.replaceImageEmbed(
Expand All @@ -190,12 +187,9 @@ func (svc Services) ProcessGDocsDoc(ctx context.Context, dbDoc db.GDocsDoc) (err
warnings = append(warnings, warning)
} else {
embed.Value = *imageEmbed
embeds = append(embeds, embed)
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)
n++
goto append
}

case "metadata", "info":
if warning := svc.replaceMetadata(
ctx, tbl, rows, dbDoc.ExternalID, objID2Path, &metadata,
Expand All @@ -214,17 +208,21 @@ func (svc Services) ProcessGDocsDoc(ctx context.Context, dbDoc db.GDocsDoc) (err
case "toc", "table of contents":
embed.Type = db.ToCEmbedTag
embed.Value = processToc(docHTML, rows)
embeds = append(embeds, embed)
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)
n++
goto append

default:
warnings = append(warnings, fmt.Sprintf(
"Unrecognized table type: %q", label,
))
tbl.Parent.RemoveChild(tbl)
}
continue
append:
embeds = append(embeds, embed)
value := must.Get(json.Marshal(embed))
data := xhtml.New("data", "value", string(value))
xhtml.ReplaceWith(tbl, data)
n++
}

docHTML, err = blocko.Minify(xhtml.ToBuffer(docHTML))
Expand Down

0 comments on commit ca938ed

Please sign in to comment.