Grails 中的 XML 站点地图

发布于 2024-09-24 17:34:08 字数 276 浏览 1 评论 0原文

我正在尝试找出生成 XML 站点地图的最佳方法(如下所述: http://www.sitemaps.org /)用于 Grails 应用程序。我不知道任何现有的插件可以做到这一点,所以我可能会构建一个。但是,我想首先获得社区的意见。除了支持标准控制器/操作之外,我认为支持内容驱动的应用程序以及可能基于标题属性生成 URL 的应用程序会很好。

你们会怎么做呢?您会考虑什么以及如何实施?

谢谢!

I am trying to figure out the best way to generate an XML sitemap (as described here: http://www.sitemaps.org/) for a Grails application. I am not aware of any existing plugins that do this so I might build one. However, I wanted to get the community's input first. Aside from supporting standard controllers/actions, I am thinking it would be nice to support content driven apps as well where the URL might be generated based on a title property for example.

How would you guys go about this? What would you consider and how would you implement it?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谎言月老 2024-10-01 17:34:08

站点地图对于每个应用程序来说都是非常特定的,因此我不确定是否有足够的通用代码可以提取到插件中。

以下是我们为 http://www.shareyourlove.com 生成站点地图的方法。正如您所看到的,由于 Groovy/Grails 良好的 XML 语法

class SitemapController{

        def sitemap = {
            render(contentType: 'text/xml', encoding: 'UTF-8') {
                mkp.yieldUnescaped '<?xml version="1.0" encoding="UTF-8"?>'
                urlset(xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
                        'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance",
                        'xsi:schemaLocation': "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd") {
                    url {
                        loc(g.createLink(absolute: true, controller: 'home', action: 'view'))
                        changefreq('hourly')
                        priority(1.0)
                    }
                    //more static pages here
                    ...
                    //add some dynamic entries
                    SomeDomain.list().each {domain->
                    url {
                        loc(g.createLink(absolute: true, controller: 'some', action: 'view', id: domain.id))
                        changefreq('hourly')
                        priority(0.8)
                    }
                }
           }
    }

URL 映射,它非常简单且干燥

class UrlMappings {
    static mappings = {

        "/sitemap"{
            controller = 'sitemap'
            action = 'sitemap'
        }
    }
}

Sitemaps are pretty specific to each app so I'm not sure if there is enough common code to pull out to a plugin.

Here is how we generate our sitemap for http://www.shareyourlove.com. As you can see it's pretty minimal and DRY due to Groovy/Grails's nice XML syntax

class SitemapController{

        def sitemap = {
            render(contentType: 'text/xml', encoding: 'UTF-8') {
                mkp.yieldUnescaped '<?xml version="1.0" encoding="UTF-8"?>'
                urlset(xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
                        'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance",
                        'xsi:schemaLocation': "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd") {
                    url {
                        loc(g.createLink(absolute: true, controller: 'home', action: 'view'))
                        changefreq('hourly')
                        priority(1.0)
                    }
                    //more static pages here
                    ...
                    //add some dynamic entries
                    SomeDomain.list().each {domain->
                    url {
                        loc(g.createLink(absolute: true, controller: 'some', action: 'view', id: domain.id))
                        changefreq('hourly')
                        priority(0.8)
                    }
                }
           }
    }

URL Mappings

class UrlMappings {
    static mappings = {

        "/sitemap"{
            controller = 'sitemap'
            action = 'sitemap'
        }
    }
}
灼痛 2024-10-01 17:34:08

我正在使用 UrlMappings.groovy 在 Grails 上制作站点地图,并且这种做法不需要控制器。我将下一个代码放入 UrlMappings 中:

"/robots.txt" (view: "/robots")
"/sitemap.xml" (view: "/sitemap")

并使用 xml 编码将站点地图创建为 gsp,例如 sitemap.gsp:

<?xml version="1.0" encoding="UTF-8"?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

   <url>

      <loc>http://www.putYourSite.com.py/</loc>

      <lastmod>putAdate</lastmod>

      <changefreq>daily</changefreq>

      <priority>1.0</priority>

   </url>

</urlset>

I was doing a sitemap on Grails with a UrlMappings.groovy and does not need a controller for this practice. I putted the next code in the UrlMappings:

"/robots.txt" (view: "/robots")
"/sitemap.xml" (view: "/sitemap")

And I create my sitemap as gsp with xml encoding, example of sitemap.gsp:

<?xml version="1.0" encoding="UTF-8"?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

   <url>

      <loc>http://www.putYourSite.com.py/</loc>

      <lastmod>putAdate</lastmod>

      <changefreq>daily</changefreq>

      <priority>1.0</priority>

   </url>

</urlset>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文