Giter VIP home page Giter VIP logo

Comments (21)

ekalinin avatar ekalinin commented on August 19, 2024

Here's example from tests:

    var smap = sm.createSitemap({
          urls: [{
              url: 'http://test.com/page-1/',
              changefreq: 'weekly',
              priority: 0.3,
              links: [
                  { lang: 'en', url: 'http://test.com/page-1/', },
                  { lang: 'ja', url: 'http://test.com/page-1/ja/', },
              ]
          },]
        });

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

But, yeah, will add this snippet into README.

from sitemap.js.

yagobski avatar yagobski commented on August 19, 2024

Hi thanks for your explain but when we install the module using npm the version 0.9.0 don't have links capability.

Try to install the module using npm install sitemap

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

Just released 1.0.0 version.
Try it, please.

from sitemap.js.

yagobski avatar yagobski commented on August 19, 2024

I update it is working only whitout links. It generate not xml sitemap. When i remove Links it works!
You have passed the test?

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

I update it is working only whitout links. It generate not xml sitemap. When i remove Links it works!

Would you be able to provide an example?

You have passed the test?

Yep:

➥ make test
./node_modules/expresso/bin/expresso ./tests/sitemap.test.js

   100% 28 tests

from sitemap.js.

yagobski avatar yagobski commented on August 19, 2024

This is my object structure :


[ { url: 'song/bari-niich',
changefreq: 'weekly',
priority: 0.6,
links:
[ { lang: 'fr', url: 'song/bari-niich' },
{ lang: 'en', url: 'song/en/bari-niich' },
{ lang: 'ar', url: 'song/ar/باغي-نعيش-1' } ] } ]


If i remove links it works.

links:
[ { lang: 'fr', url: 'song/bari-niich' },
{ lang: 'en', url: 'song/en/bari-niich' },
{ lang: 'ar', url: 'song/ar/باغي-نعيش-1' } ]

from sitemap.js.

yagobski avatar yagobski commented on August 19, 2024

This is my code :

var options = {
            hostname: config.clientUrl,
            cacheTime: 600000,        // 600 sec - cache purge period
            urls: [{
                url: 'http://test.com/page-1/',
                changefreq: 'weekly',
                priority: 0.3,
                links: [
                    { lang: 'en', url: 'http://test.com/page-1/', },
                    { lang: 'ja', url: 'http://test.com/page-1/ja/', },
                ]
            },]
        };

        var sm = require('sitemap');
        var sitemap = sm.createSitemap(options);

        sitemap.toXML( function(xml){
            cb(null,xml);
        });

I get output like this (non xml) :

http://test.com/page-1/ weekly 0.3

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

Here's my try:

➥ node -v
v0.12.0
> var options = {
...     hostname: 'http://test.com',
...     cacheTime: 600000,        // 600 sec - cache purge period
...     urls: [{
.....         url: 'http://test.com/page-1/',
.....         changefreq: 'weekly',
.....         priority: 0.3,
.....         links: [
.....             { lang: 'en', url: 'http://test.com/page-1/', },
.....             { lang: 'ja', url: 'http://test.com/page-1/ja/', },
.....         ]
.....     },]
... };
undefined
> 
undefined
> var sm = require('./index');
undefined
> var sitemap = sm.createSitemap(options);
undefined
> sm.version
'1.0.0'
> 
undefined
> sitemap.toString();
'<?xml version="1.0" encoding="UTF-8"?>\n
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 
xmlns:xhtml="http://www.w3.org/1999/xhtml"
 xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">\n
  <url>
    <loc>http://test.com/page-1/</loc>
    <changefreq>weekly</changefreq> 
    <priority>0.3</priority>
    <xhtml:link rel="alternate" hreflang="en" href="http://test.com/page-1/" />
    <xhtml:link rel="alternate" hreflang="ja" href="http://test.com/page-1/ja/" />
  </url>\n
</urlset>'

from sitemap.js.

yagobski avatar yagobski commented on August 19, 2024

Ok thanks i will try to fix my code :) sorry about that

from sitemap.js.

yagobski avatar yagobski commented on August 19, 2024

It works for me now. It was the sitemap.toXML

Thanks again

from sitemap.js.

seanmthompson avatar seanmthompson commented on August 19, 2024

I know this is closed but I'm experience the same bug. When I add locale links, the XML returned seems formatted incorrectly. See attached images. One without "links" added, one with them. Notice Chrome does not render one them. I've followed the example exactly so not sure what I'm doing wrong here.
screen shot 2015-11-19 at 11 41 16 am
screen shot 2015-11-19 at 11 40 58 am

    var options = {
     hostname: 'http://test.com',
     cacheTime: 600000,        // 600 sec - cache purge period
     urls: [{
         url: 'http://test.com/page-1/',
         changefreq: 'weekly',
         priority: 0.3
     },]
};

var sitemap = sm.createSitemap(options);

app.get('/sitemap.xml', function(req, res) {
  res.header('Content-Type', 'application/xml');
  res.send(sitemap.toString());
});

And with links:
var options = {
hostname: 'http://test.com',
cacheTime: 600000, // 600 sec - cache purge period
urls: [{
url: 'http://test.com/page-1/',
changefreq: 'weekly',
priority: 0.3,
links: [
{ lang: 'en', url: 'http://test.com/page-1/', },
{ lang: 'ja', url: 'http://test.com/page-1/ja/', },
]
},]
};

var sitemap = sm.createSitemap(options);

app.get('/sitemap.xml', function(req, res) {
  res.header('Content-Type', 'application/xml');
  res.send(sitemap.toString());
});

from sitemap.js.

lenovouser avatar lenovouser commented on August 19, 2024

I have the same problem like @seanmthompson's

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

Hi @seanmthompson and @lenovouser,

Thanks for report.
What versions of the node and sitemap.js did you use?

Here's my try:

Init:

➥ virtualenv env
➥ . env/bin/activate
➥ pip install nodeenv
➥ nodeenv -p --prebuilt
➥ npm install sitemap
➥ npm ls | grep sitemap
└─┬ [email protected]
➥ node -v
v5.1.0

Test:

➥ cat testing.js 
var options = {
    hostname: 'http://test.com',
    cacheTime: 600000, // 600 sec - cache purge period
    urls: [{
            url: 'http://test.com/page-1/',
            changefreq: 'weekly',
            priority: 0.3,
            links: [
                { lang: 'en', url: 'http://test.com/page-1/', },
                { lang: 'ja', url: 'http://test.com/page-1/ja/', },
            ]
    },]
};
var sm = require('sitemap');
var sitemap = sm.createSitemap(options);
console.log(sitemap.toString());

➥ node testing.js | xmllint --format -
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <url>
    <loc>http://test.com/page-1/</loc>
    <changefreq>weekly</changefreq>
    <priority>0.3</priority>
    <xhtml:link rel="alternate" hreflang="en" href="http://test.com/page-1/"/>
    <xhtml:link rel="alternate" hreflang="ja" href="http://test.com/page-1/ja/"/>
  </url>
</urlset>

from sitemap.js.

florianlebrenn avatar florianlebrenn commented on August 19, 2024

Same issue with expressjs (4.14.0), node (7.3.0) and sitemap.js (1.9.0).

app.get('/sitemap.xml', function(req, res) {
  var hostname = req.protocol + '://' + req.get('host');
  var sitemap = sm.createSitemap ({
    cacheTime: 600000,        // 600 sec - cache purge period
    hostname: hostname,
    urls: [
      {
        url: hostname + '/',
        changefreq: 'weekly',
        links: [
          { lang: 'fr', url: hostname + '/', },
          { lang: 'en', url: hostname + '/en/', }
        ],
        priority: 0.7
      },
      {
        url: hostname + '/agence/',
        changefreq: 'weekly',
        links: [
          { lang: 'fr', url: hostname + '/agence/', },
          { lang: 'en', url: hostname + '/agency/', }
        ],
        priority: 0.7
      }
    ]
  });

  res.header('Content-Type', 'application/xml');
  res.send( sitemap.toString() );
});
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url> <loc>http://localhost:3000/</loc> <changefreq>weekly</changefreq> <priority>0.7</priority> <xhtml:link rel="alternate" hreflang="fr" href="http://localhost:3000/" /> <xhtml:link rel="alternate" hreflang="en" href="http://localhost:3000/en/" /> </url>
<url> <loc>http://localhost:3000/agence/</loc> <changefreq>weekly</changefreq> <priority>0.7</priority> <xhtml:link rel="alternate" hreflang="fr" href="http://localhost:3000/agence/" /> <xhtml:link rel="alternate" hreflang="en" href="http://localhost:3000/agency/" /> </url>
</urlset>

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

Hey @florianlebrenn

Could you provide more details? What is wrong with this response?
As i see xml is valid and all lang links are in the place.

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

Clear setup:

➥ virtualenv env
➥ . env/bin/activate
➥ pip install nodeenv
➥ nodeenv -p --prebuilt
 * Install prebuilt node (7.7.1) ..... done.
 * Appending data to ~/tmp/sitemap-test/env/bin/activate
➥ npm install sitemap
➥ npm ls
~/tmp/sitemap-test
└─┬ [email protected]
  ├── [email protected]
  └── [email protected]
➥ node -v
v7.7.1

Code:

 cat testing2.js 
var hostname = 'https://true.example.com';

var sm = require('sitemap');
var sitemap = sm.createSitemap ({
    cacheTime: 600000,        // 600 sec - cache purge period
    hostname: hostname,
    urls: [
      {
        url: hostname + '/',
        changefreq: 'weekly',
        links: [
          { lang: 'fr', url: hostname + '/', },
          { lang: 'en', url: hostname + '/en/', }
        ],
        priority: 0.7
      },
      {
        url: hostname + '/agence/',
        changefreq: 'weekly',
        links: [
          { lang: 'fr', url: hostname + '/agence/', },
          { lang: 'en', url: hostname + '/agency/', }
        ],
        priority: 0.7
      }
    ]
  });

console.log(sitemap.toString());

Test:

➥ node testing2.js | xmllint --format -
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <url>
    <loc>https://true.example.com/</loc>
    <changefreq>weekly</changefreq>
    <priority>0.7</priority>
    <xhtml:link rel="alternate" hreflang="fr" href="https://true.example.com/"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://true.example.com/en/"/>
  </url>
  <url>
    <loc>https://true.example.com/agence/</loc>
    <changefreq>weekly</changefreq>
    <priority>0.7</priority>
    <xhtml:link rel="alternate" hreflang="fr" href="https://true.example.com/agence/"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://true.example.com/agency/"/>
  </url>
</urlset>

LGTM :)

from sitemap.js.

florianlebrenn avatar florianlebrenn commented on August 19, 2024

Hello @ekalinin,

Thanks for your answer. When I try to display sitemap.xml from chrome. I see the same result than @seanmthompson : https://cloud.githubusercontent.com/assets/5447621/11282132/9320b82a-8eb2-11e5-926d-27bd2dd9ce91.png. Without "links", the sitemap result is displayed correctly by chrome (I can see xml code like this https://cloud.githubusercontent.com/assets/5447621/11282131/931fd086-8eb2-11e5-87d2-8b6114e38754.png).

Could you confirm to me the sitemap is valid even if chrome doesn't render correctly this xml response ?

from sitemap.js.

ekalinin avatar ekalinin commented on August 19, 2024

Hey @florianlebrenn

Yeah, seems like something wrong with Chrome's XML Viewer.
Current xml format corresponds to the google's spec:

2017-03-03_10 49 20_001

Moreover, on this sites I've had a response that this XML is valid:

  • xmlvalidation.com
  • w3schools.com/xml/xml_validator.asp

And finally, xmllint as it was shown earlier have no complains as well.

from sitemap.js.

florianlebrenn avatar florianlebrenn commented on August 19, 2024

Hello @ekalinin

Thanks. Have a good day.

from sitemap.js.

yshterev avatar yshterev commented on August 19, 2024

@ekalinin @florianlebrenn
A discussion on why the browsers don't render pretty XML in this case:
https://bugs.chromium.org/p/chromium/issues/detail?id=580033

Long story short.. xmlns:xhtml="http://www.w3.org/1999/xhtml + xhtml:link in links puts the browsers parser in XHTML mode and the XML is parsed as XHTML document.

from sitemap.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.