Skip to content

Commit

Permalink
v9.7.0 (#807)
Browse files Browse the repository at this point in the history
* routing func support (#806)

* fix typo in defer documentation

* AppendClass helper takes variadic parameters

* Update README.md

* No wasm mode (#810)

* query parameter to see a page without wasm

* pre render at same depth as render

* remove loader node rather than hide it

* Update html.go

* Update html.go

* prevent loader to show in non wasm mode

* cleanup

* load all styles before scripts

* load ga async

* remove not used css

* reduce generated html size

* reduce html size further

* reduce generated html size 3

* handler preconnect link

* src multiple call support + fix resolving

* test srcset attribute

* update deps

* fix html resolve attribute URL

* enriched http handler src

* fix preconnect default crossorigin

* update doc

* Remove pre render caching (#818)

* Remove PreRenderCache and PreRenderCacheControl

* rename and clean cache related items

* rename pre rendered item and use proxy cached items

* rename http pwaResources to cachePWAResources

* ignore empty attribute value when generating html string

* fix ignore empty attr when generating html

* revert attr filter

* preload styles

* generated html don't add resources without url

* preload right after preconnect

* add preload font support

* fix font preload type

* fix font resolver

* add font to cacheable resources

* Optimize html gen (#827)

* don't genrate html with empty id or class

* fix condition

* refactor write html attribute

* Update html_test.go

* Datset with map (#828)

* don't genrate html with empty id or class

* fix condition

* refactor write html attribute

* dataset with a map

* preload font first

* change loader display

* fix server side resource resolver

* Update page_test.go

* twitter card page support

* remove expired persisted states (#837)
  • Loading branch information
maxence-charriere authored Jun 27, 2023
1 parent db6035c commit ae6abf8
Show file tree
Hide file tree
Showing 35 changed files with 2,146 additions and 459 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">
<a href="https://go-app.dev">
<img alt="go-app" width="150" height="150" src="https://storage.googleapis.com/murlok-github/icon-192.png">
<img alt="go-app" width="150" height="150" src="docs/web/icon.png">
</a>
</h1>

Expand Down
8 changes: 4 additions & 4 deletions docs/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ func main() {
BackgroundColor: backgroundColor,
ThemeColor: backgroundColor,
LoadingLabel: "go-app documentation {progress}%",
Scripts: []string{
"/web/js/prism.js",
},
Styles: []string{
"https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500&display=swap",
"/web/css/prism.css",
"/web/css/docs.css",
},
Scripts: []string{
"/web/js/prism.js defer",
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1013306768105236 async crossorigin=anonymous",
},
RawHeaders: []string{
`<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1013306768105236" crossorigin="anonymous"></script>`,
analytics.GoogleAnalyticsHeader("G-SW4FQEM9VM"),
},
CacheableResources: []string{
Expand Down
Binary file modified docs/web/app.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/web/documents/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (f *foo) OnNav(ctx app.Context) {
## Defer

```go
func (c *Compo) Defer(fn func(Context))
func (ctx Context) Defer(fn func(Context))
```

[Defer()](/reference#Compo.Defer) is a [Compo](/reference#Compo) method that like [Dispatch()](#dispatch), executes a given function on the [UI goroutine](#ui-goroutine). The difference is that the given function is executed after a component has its UI updated.
Expand Down
79 changes: 59 additions & 20 deletions docs/web/documents/reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@



<script>var goVersion = "go1.19.5";</script>
<script>var goVersion = "go1.20.1";</script>
<script src="/lib/godoc/godocs.js" defer></script>
</head>
<body>
Expand Down Expand Up @@ -125,7 +125,7 @@ <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>



<dd><a href="#AppendClass">func AppendClass(class, c string) string</a></dd>
<dd><a href="#AppendClass">func AppendClass(class string, v ...string) string</a></dd>


<dd><a href="#Broadcast">func Broadcast(s *State)</a></dd>
Expand Down Expand Up @@ -176,9 +176,15 @@ <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
<dd><a href="#Route">func Route(path string, c Composer)</a></dd>


<dd><a href="#RouteFunc">func RouteFunc(path string, newComponent func() Composer)</a></dd>


<dd><a href="#RouteWithRegexp">func RouteWithRegexp(pattern string, c Composer)</a></dd>


<dd><a href="#RouteWithRegexpFunc">func RouteWithRegexpFunc(pattern string, newComponent func() Composer)</a></dd>


<dd><a href="#RunWhenOnBrowser">func RunWhenOnBrowser()</a></dd>


Expand Down Expand Up @@ -1566,13 +1572,13 @@ <h2 id="pkg-variables">Variables</h2>



<h2 id="AppendClass">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/strings.go?s=1795:1835#L104">AppendClass</a>
<h2 id="AppendClass">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/strings.go?s=1689:1739#L96">AppendClass</a>
<a class="permalink" href="#AppendClass">&#xb6;</a>


</h2>
<pre>func AppendClass(class, c <a href="/pkg/builtin/#string">string</a>) <a href="/pkg/builtin/#string">string</a></pre>
<p>AppendClass adds c to the given class string.
<pre>func AppendClass(class <a href="/pkg/builtin/#string">string</a>, v ...<a href="/pkg/builtin/#string">string</a>) <a href="/pkg/builtin/#string">string</a></pre>
<p>AppendClass adds values to the given class string.



Expand Down Expand Up @@ -1811,33 +1817,59 @@ <h2 id="PrintHTMLWithIndent">func <a href="/src/github.com/maxence-charriere/go-



<h2 id="Route">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/route.go?s=287:322#L7">Route</a>
<h2 id="Route">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/route.go?s=182:217#L5">Route</a>
<a class="permalink" href="#Route">&#xb6;</a>


</h2>
<pre>func Route(path <a href="/pkg/builtin/#string">string</a>, c <a href="#Composer">Composer</a>)</pre>
<p>Route associates the type of the given component to the given path.
<p>When a page is requested and matches the route, a new instance of the given
component is created before being displayed.
<p>Route set the type of component to be mounted when a page is navigated to the
given path.







<h2 id="RouteWithRegexp">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/route.go?s=639:687#L18">RouteWithRegexp</a>
<h2 id="RouteFunc">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/route.go?s=620:677#L18">RouteFunc</a>
<a class="permalink" href="#RouteFunc">&#xb6;</a>


</h2>
<pre>func RouteFunc(path <a href="/pkg/builtin/#string">string</a>, newComponent func() <a href="#Composer">Composer</a>)</pre>
<p>RouteFunc set a function that creates the component to be mounted when a page
is navigated to the given path.







<h2 id="RouteWithRegexp">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/route.go?s=394:442#L11">RouteWithRegexp</a>
<a class="permalink" href="#RouteWithRegexp">&#xb6;</a>


</h2>
<pre>func RouteWithRegexp(pattern <a href="/pkg/builtin/#string">string</a>, c <a href="#Composer">Composer</a>)</pre>
<p>RouteWithRegexp associates the type of the given component to the given
regular expression pattern.
<p>Patterns use the Go standard regexp format.
<p>When a page is requested and matches the pattern, a new instance of the given
component is created before being displayed.
<p>RouteWithRegexp set the type of component to be mounted when a page is
navigated to a path that matches the given pattern.







<h2 id="RouteWithRegexpFunc">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/route.go?s=866:936#L24">RouteWithRegexpFunc</a>
<a class="permalink" href="#RouteWithRegexpFunc">&#xb6;</a>


</h2>
<pre>func RouteWithRegexpFunc(pattern <a href="/pkg/builtin/#string">string</a>, newComponent func() <a href="#Composer">Composer</a>)</pre>
<p>RouteWithRegexpFunc set a function that creates the component to be mounted
when a page is navigated to a path that matches the given pattern.



Expand Down Expand Up @@ -2787,7 +2819,7 @@ <h2 id="Dispatcher">type <a href="/src/github.com/maxence-charriere/go-app/v9/pk



<h2 id="Environment">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=20982:21016#L856">Environment</a>
<h2 id="Environment">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=22153:22187#L903">Environment</a>
<a class="permalink" href="#Environment">&#xb6;</a>


Expand Down Expand Up @@ -24968,7 +25000,7 @@ <h3 id="Wbr">func <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/h



<h2 id="Handler">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=480:5153#L22">Handler</a>
<h2 id="Handler">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=469:5488#L21">Handler</a>
<a class="permalink" href="#Handler">&#xb6;</a>


Expand Down Expand Up @@ -25093,6 +25125,13 @@ <h2 id="Handler">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/a
<span class="comment">// would be the URL for an OAuth authentication.</span>
<span id="Handler.InternalURLs"></span> InternalURLs []<a href="/pkg/builtin/#string">string</a>

<span class="comment">// The URLs of the origins to preconnect in order to improve the user</span>
<span class="comment">// experience by preemptively initiating a connection to those origins.</span>
<span class="comment">// Preconnecting speeds up future loads from a given origin by preemptively</span>
<span class="comment">// performing part or all of the handshake (DNS+TCP for HTTP, and</span>
<span class="comment">// DNS+TCP+TLS for HTTPS origins).</span>
<span id="Handler.Preconnect"></span> Preconnect []<a href="/pkg/builtin/#string">string</a>

<span class="comment">// The cache that stores pre-rendered pages.</span>
<span class="comment">//</span>
<span class="comment">// Default: A LRU cache that keeps pages up to 24h and have a maximum size</span>
Expand Down Expand Up @@ -25152,7 +25191,7 @@ <h2 id="Handler">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/a



<h3 id="Handler.ServeHTTP">func (*Handler) <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=13065:13132#L520">ServeHTTP</a>
<h3 id="Handler.ServeHTTP">func (*Handler) <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=13511:13578#L532">ServeHTTP</a>
<a class="permalink" href="#Handler.ServeHTTP">&#xb6;</a>


Expand All @@ -25166,7 +25205,7 @@ <h3 id="Handler.ServeHTTP">func (*Handler) <a href="/src/github.com/maxence-char



<h2 id="Icon">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=20305:20890#L830">Icon</a>
<h2 id="Icon">type <a href="/src/github.com/maxence-charriere/go-app/v9/pkg/app/http.go?s=21476:22061#L877">Icon</a>
<a class="permalink" href="#Icon">&#xb6;</a>


Expand Down Expand Up @@ -26795,7 +26834,7 @@ <h2 id="pkg-subdirectories">Subdirectories</h2>


<div id="footer">
Build version go1.19.5.<br>
Build version go1.20.1.<br>
Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ go 1.18

require (
github.com/SherClockHolmes/webpush-go v1.2.0
github.com/gomarkdown/markdown v0.0.0-20220607163217-45f7c050e2d1
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c
github.com/google/uuid v1.3.0
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20220615171555-694bf12d69de
golang.org/x/net v0.7.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/crypto v0.6.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keL
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/gomarkdown/markdown v0.0.0-20220607163217-45f7c050e2d1 h1:wAupuFkZ/yq219/mSbqDtMfUZQY0gTYEtoz3/LKtppU=
github.com/gomarkdown/markdown v0.0.0-20220607163217-45f7c050e2d1/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c h1:iyaGYbCmcYK0Ja9a3OUa2Fo+EaN0cbLu0eKpBwPFzc8=
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -16,8 +18,12 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/net v0.0.0-20220615171555-694bf12d69de h1:ogOG2+P6LjO2j55AkRScrkB2BFpd+Z8TY2wcM0Z3MGo=
golang.org/x/net v0.0.0-20220615171555-694bf12d69de/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
3 changes: 1 addition & 2 deletions pkg/analytics/google-analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// field to initialize Google Analytics.
func GoogleAnalyticsHeader(propertyID string) string {
return fmt.Sprintf(`<!-- Global site tag (gtag.js) - Google Analytics -->
<script defer src="https://www.googletagmanager.com/gtag/js?id=%s"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=%s"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
Expand All @@ -25,7 +25,6 @@ func NewGoogleAnalytics() Backend {
}

type googleAnalytics struct {
propertyID string
}

func (a googleAnalytics) Identify(userID string, traits map[string]interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func RunWhenOnBrowser() {
StaticResourceResolver: staticResourcesResolver,
ActionHandlers: actionHandlers,
}
disp.Page = browserPage{dispatcher: &disp}
disp.Page = browserPage{resolveStaticResource: staticResourcesResolver}
disp.Body = newClientBody(&disp)
disp.init()
defer disp.Close()
Expand Down
20 changes: 16 additions & 4 deletions pkg/app/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ func (a attributes) Set(name string, value any) {
if s != "" {
s += " "
}
s += toAttributeValue(value)
a[name] = s
a[name] = s + toAttributeValue(value)

case "srcset":
s := a[name]
if s != "" {
s += ", "
}
a[name] = s + toAttributeValue(value)

default:
a[name] = toAttributeValue(value)
Expand Down Expand Up @@ -68,10 +74,16 @@ func resolveAttributeURLValue(name, value string, resolve attributeURLResolver)
case "cite",
"data",
"href",
"src",
"srcset":
"src":
return resolve(value)

case "srcset":
srcs := strings.Split(value, ", ")
for i, src := range srcs {
srcs[i] = resolve(src)
}
return strings.Join(srcs, ", ")

default:
return value
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/app/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ func TestAttributesSet(t *testing.T) {
require.Equal(t, "foo bar", attributes["class"])
})

t.Run("set srcset", func(t *testing.T) {
attributes := make(attributes)
attributes.Set("srcset", "/hi")
require.Equal(t, "/hi", attributes["srcset"])
})

t.Run("set multiple srcset", func(t *testing.T) {
attributes := make(attributes)
attributes.Set("srcset", "/hi")
attributes.Set("srcset", "/bye")
require.Equal(t, "/hi, /bye", attributes["srcset"])
})

t.Run("set common attribute", func(t *testing.T) {
attributes := make(attributes)
attributes.Set("value", "foo")
Expand Down Expand Up @@ -140,6 +153,11 @@ func TestResolveAttributeURLValue(t *testing.T) {
value: "bar",
resolvedValue: "/foo/bar",
},
{
name: "srcset",
value: "hi, bye",
resolvedValue: "/foo/hi, /foo/bye",
},
}

for _, u := range utests {
Expand Down
Loading

0 comments on commit ae6abf8

Please sign in to comment.