| 138 | } |
| 139 | |
| 140 | func FormatLinkNofollow(html string) string { |
| 141 | var hrefRegexp = regexp.MustCompile("(?m)<a.*?[^<]>.*?</a>") |
| 142 | match := hrefRegexp.FindAllString(html, -1) |
| 143 | for _, v := range match { |
| 144 | hasNofollow := strings.Contains(v, "rel=\"nofollow\"") |
| 145 | hasSiteUrl := strings.Contains(v, controller.SiteUrl) |
| 146 | if !hasSiteUrl { |
| 147 | if !hasNofollow { |
| 148 | nofollowUrl := strings.Replace(v, "<a", "<a rel=\"nofollow\"", 1) |
| 149 | html = strings.Replace(html, v, nofollowUrl, 1) |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | return html |
| 154 | } |