MCPcopy Create free account
hub / github.com/GuyARoss/orbit / buildHTMLPages

Function buildHTMLPages

examples/basic-react/orbitgen/orb_http.go:58–95  ·  view source on GitHub ↗

build buildHTMLPages creates the htmldocument given data for orbits manifest and the page's

(data []byte, pages ...PageRender)

Source from the content-addressed store, hash-verified

56}
57// build buildHTMLPages creates the htmldocument given data for orbits manifest and the page's
58func buildHTMLPages(data []byte, pages ...PageRender) *htmlDoc {
59 body := make([]string, 0)
60 head := make([]string, 0)
61 isWrapped := make(map[string]bool)
62 for _, p := range pages {
63 // if the page is of static origin, we first check to see if it exists on the file system
64 // if it does, it will be applied to the current html document, rather than returned directly
65 // this is to support the usage of static html within micro-frontends
66 if staticResourceMap[p] {
67 staticDocument, err := parseStaticDocument(fmt.Sprintf("%s%c%s", http.Dir(bundleDir), os.PathSeparator, p))
68 if err == nil {
69 body = append(body, innerHTML(string(staticDocument), "<body>", "</body>"))
70 head = append(head, innerHTML(string(staticDocument), "<head>", "</head>"))
71 continue
72 }
73 }
74 // wrapping page content should only happen once as it just creates
75 // the requirements for the specific web wrapper to work correctly
76 pv := wrapDocRender[p]
77 if pv != nil && !isWrapped[pv.version] {
78 isWrapped[pv.version] = true
79 for _, b := range pageDependencies[p] {
80 head = append(head, b)
81 }
82 }
83 }
84 html := &htmlDoc{
85 Head: head,
86 Body: body,
87 }
88 ctx := context.Background()
89 for _, p := range pages {
90 if op := wrapDocRender[p]; op != nil {
91 html, ctx = op.fn(ctx, string(p), data, html)
92 }
93 }
94 return html
95}
96// innerHTML is a utility function that assists with the parsing the content of html tags
97// it does this by returning the subset of the two provided strings "subStart" & "subEnd"
98func innerHTML(str string, subStart string, subEnd string) string {

Callers 2

TestBuildHTMLPagesFunction · 0.70
HandleFuncMethod · 0.70

Calls 2

parseStaticDocumentFunction · 0.70
innerHTMLFunction · 0.70

Tested by 1

TestBuildHTMLPagesFunction · 0.56