Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix go-sitemap-generator overriding GOMAXPROCs #141

Merged
merged 3 commits into from Aug 2, 2019
Merged

Conversation

thebaer
Copy link
Member

@thebaer thebaer commented Jul 20, 2019

This upgrades the go-sitemap-generator library to v2, which lets you specify that GOMAXPROCs should always be the max number of CPUs -- and then sets it to that.

One side effect of this is that images are no longer listed in sitemaps. I'm somehow at a loss on how to build and append the images array we need, with the library's latest changes. Ideally we'd fix this -- any help would be much appreciated.

Fixes #86

This upgrades the library to v2, which lets you specify that GOMAXPROCs
should always be the max number of CPUs -- and then sets it to that.

One side effect of this is that images are no longer listed in sitemaps.
I'm somehow at a loss on how to build and append the images array we
need, with the library's latest changes.

Fixes #86
@thebaer thebaer added this to the 0.11 milestone Jul 20, 2019
sitemap.go Outdated
imgs = append(imgs, stm.URL{{"loc", i}, {"title", ""}})
}
// FIXME: this is a pain. At a loss on how to do this
u = append(u, []interface{}{[]interface{}{"image": imgs}})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robjloranger Could you help out with this whenever you have a chance?

changed to use stm.URL for imgs for readability
fixed error in append statement
reordered import statements
@thebaer
Copy link
Member Author

thebaer commented Aug 1, 2019

Thanks for taking a look, @robjloranger. Now when I try to get the sitemap on a blog that has posts which include images, I get this error:

ERROR: 2019/08/01 14:51:41 log.go:26: interface conversion: interface {} is []interface {}, not string:
goroutine 165 [running]:
runtime/debug.Stack(0xc0008852b8, 0x1744660, 0xc00097aba0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/writeas/writefreely.(*Handler).AllReader.func1.1.1(0x1a7bc60, 0xc0008aa0e0, 0xc000885b20, 0xc00055ff00, 0xbf48eb0f590cb1f7, 0x9838ab86a4d, 0x2eb7f20)
        /home/mattbaer/projects/go/src/github.com/writeas/writefreely/handle.go:560 +0x26f
panic(0x1744660, 0xc00097aba0)
        /usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/ikeikeikeike/go-sitemap-generator/v2/stm.SetBuilderElementValue(0xc000597f80, 0xc00091c600, 0x6, 0x8, 0x18c90be, 0x5, 0x0, 0x0)
        /home/mattbaer/projects/go/pkg/mod/github.com/ikeikeikeike/go-sitemap-generator/v2@v2.0.2/stm/utils.go:140 +0x158f
github.com/ikeikeikeike/go-sitemap-generator/v2/stm.(*sitemapURL).XML(0xc0008a65e0, 0x0, 0x0, 0xc0008857f8)
        /home/mattbaer/projects/go/pkg/mod/github.com/ikeikeikeike/go-sitemap-generator/v2@v2.0.2/stm/builder_url.go:116 +0x375
github.com/ikeikeikeike/go-sitemap-generator/v2/stm.(*BuilderFile).Add(0xc0003d8340, 0x1739880, 0xc0008a6580, 0xc000dcc000, 0x416d7d)
        /home/mattbaer/projects/go/pkg/mod/github.com/ikeikeikeike/go-sitemap-generator/v2@v2.0.2/stm/builder_file.go:48 +0x2a2
github.com/ikeikeikeike/go-sitemap-generator/v2/stm.(*Sitemap).Add(0xc0005c67e0, 0x1739880, 0xc0008a6580, 0xc0008a6580)
        /home/mattbaer/projects/go/pkg/mod/github.com/ikeikeikeike/go-sitemap-generator/v2@v2.0.2/stm/sitemap.go:90 +0x57
github.com/writeas/writefreely.handleViewSitemap(0xc0004a2730, 0x1a7bc60, 0xc0008aa0e0, 0xc00055ff00, 0xc000619b20, 0xc00055ff00)
        /home/mattbaer/projects/go/src/github.com/writeas/writefreely/sitemap.go:95 +0x78d
github.com/writeas/writefreely.(*Handler).AllReader.func1.1(0x1a7bc60, 0xc0008aa0e0, 0xc00055ff00, 0xc0003de2e0, 0x192d6f8, 0x0, 0x0)
        /home/mattbaer/projects/go/src/github.com/writeas/writefreely/handle.go:596 +0x123
github.com/writeas/writefreely.(*Handler).AllReader.func1(0x1a7bc60, 0xc0008aa0e0, 0xc00055ff00)
        /home/mattbaer/projects/go/src/github.com/writeas/writefreely/handle.go:606 +0x5a
net/http.HandlerFunc.ServeHTTP(0xc000522540, 0x1a7bc60, 0xc0008aa0e0, 0xc00055ff00)
        /usr/local/go/src/net/http/server.go:1995 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc0005da240, 0x1a7bc60, 0xc0008aa0e0, 0xc00055e600)
        /home/mattbaer/projects/go/pkg/mod/github.com/gorilla/mux@v1.7.0/mux.go:212 +0xe3
net/http.serverHandler.ServeHTTP(0xc000244000, 0x1a7bc60, 0xc0008aa0e0, 0xc00055e600)
        /usr/local/go/src/net/http/server.go:2774 +0xa8
net/http.(*conn).serve(0xc0001881e0, 0x1a7dc60, 0xc0004073c0)
        /usr/local/go/src/net/http/server.go:1878 +0x851
created by net/http.(*Server).Serve
        /usr/local/go/src/net/http/server.go:2884 +0x2f4

@ghost
Copy link

ghost commented Aug 1, 2019

ok I think I fixed it, I will test locally myself before pushing the commit

@ghost
Copy link

ghost commented Aug 1, 2019

<urlset xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
    <url>
        <loc>http://localhost:8080/rob/image-test</loc>
        <lastmod>2019-08-01T23:35:29Z</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
        <mobile:mobile/>
        <image:image>
            <image:loc>https://static1.srcdn.com/wordpress/wp-content/uploads/2019/07/Harley-Quinn-DC-Universe-Batman-and-Harley.jpg</image:loc>
            <image:title/>
        </image:image>
    </url>
    <url>
        <loc>http://localhost:8080/rob/testing-this-thing</loc>
        <lastmod>2019-07-01T22:03:09Z</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.5</priority>
        <mobile:mobile/>
    </url>
    <url>
        <loc>http://localhost:8080/rob/</loc>
        <lastmod>2019-08-01T23:35:29Z</lastmod>
        <changefreq>daily</changefreq>
        <priority>1.0</priority>
    </url>
</urlset>

How's this look? One post in my collection with an image results in this output with no error.

@thebaer
Copy link
Member Author

thebaer commented Aug 2, 2019

Yep, looks good!

@thebaer
Copy link
Member Author

thebaer commented Aug 2, 2019

Perfect, works for me as well! Merging now.

@thebaer thebaer merged commit 6bfc441 into develop Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Using go-sitemap-generator changes behavior of entire program
1 participant