MCPcopy Index your code
hub / github.com/TruthHun/DocHub / ImageWithoutDomain

Method ImageWithoutDomain

models/CloudStoreModel.go:314–334  ·  view source on GitHub ↗
(htmlOld string)

Source from the content-addressed store, hash-verified

312}
313
314func (c *CloudStore) ImageWithoutDomain(htmlOld string) (htmlNew string) {
315 doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlOld))
316 if err != nil {
317 helper.Logger.Error(err.Error())
318 return htmlOld
319 }
320 domain := c.GetPublicDomain()
321
322 doc.Find("img").Each(func(i int, s *goquery.Selection) {
323 // For each item found, get the band and title
324 if src, exist := s.Attr("src"); exist {
325 //不存在http开头的图片链接,则更新为绝对链接
326 if strings.HasPrefix(src, "http://") || strings.HasPrefix(src, "https://") {
327 src = strings.TrimPrefix(src, domain)
328 s.SetAttr("src", src)
329 }
330 }
331 })
332 htmlNew, _ = doc.Find("body").Html()
333 return
334}
335
336//从HTML中提取图片文件,并删除
337func (c *CloudStore) DeleteImageFromHtml(htmlStr string) {

Callers 1

EditMethod · 0.80

Calls 1

GetPublicDomainMethod · 0.95

Tested by

no test coverage detected