예제 #1
0
파일: absurl.go 프로젝트: nelsonsilva/hugo
func (t *AbsURL) absUrlify(tr *htmltran.Transformer, selectors ...elattr) (err error) {
	var baseURL, inURL *url.URL

	if baseURL, err = url.Parse(t.BaseURL); err != nil {
		return
	}

	replace := func(in string) string {
		if inURL, err = url.Parse(in); err != nil {
			return in + "?"
		}
		if fragmentOnly(inURL) {
			return in
		}
		return baseURL.ResolveReference(inURL).String()
	}

	for _, el := range selectors {
		if err = tr.Apply(htmltran.TransformAttrib(el.attr, replace), el.tag); err != nil {
			return
		}
	}

	return
}
예제 #2
0
파일: absurl.go 프로젝트: GeertJohan/hugo
func absUrlify(baseURL *url.URL, selectors ...elattr) (trs []*htmltran.Transform, err error) {
	var inURL *url.URL

	replace := func(in string) string {
		if inURL, err = url.Parse(in); err != nil {
			return in + "?"
		}
		if fragmentOnly(inURL) {
			return in
		}
		return baseURL.ResolveReference(inURL).String()
	}

	for _, el := range selectors {
		mt := htmltran.MustTrans(htmltran.TransformAttrib(el.attr, replace), el.tag)
		trs = append(trs, mt)
	}

	return
}