Comments (21)
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.
But, yeah, will add this snippet into README.
from sitemap.js.
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.
Just released 1.0.0
version.
Try it, please.
from sitemap.js.
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.
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.
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.
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.
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.
Ok thanks i will try to fix my code :) sorry about that
from sitemap.js.
It works for me now. It was the sitemap.toXML
Thanks again
from sitemap.js.
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.
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.
I have the same problem like @seanmthompson's
from sitemap.js.
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.
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.
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.
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.
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.
Hey @florianlebrenn
Yeah, seems like something wrong with Chrome's XML Viewer.
Current xml format corresponds to the google's spec:
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.
Hello @ekalinin
Thanks. Have a good day.
from sitemap.js.
@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)
- [ BUG ] Using 'links' option in an entry breaks sitemap generation HOT 10
- [Feature] Keep a record of the parent node HOT 1
- [Feature] cdn for sitemap?
- add <mobile:mobile type="pc,mobile"/>
- [question] How do we render the streamToPromise buffer response for storage in a Cache? HOT 3
- Add option for removing trailing slash from the root page HOT 4
- index with multiple categorized sitemaps HOT 5
- [Feature] Specify lastmod attribute per url link HOT 2
- [question] large sitemap, check last sitemap item and continue generate next file only? HOT 1
- [Feature] Support for custom elements in SitemapStream
- [ BUG ] Premature end of data in tag url line 1 HOT 2
- [ BUG ] Cannot set property IndexTagNames of #<Object> which has only a getter HOT 2
- [ BUG ] Sitemap not generated when url count is less than 5. HOT 3
- [question] How to append urls to existing xml?
- [question] How to allow empty sitemap? HOT 3
- [ BUG ] `SitemapAndIndexStream` hangs on end if `SitemapStream` encountered error writing to its destination
- [ BUG ] `streamToPromise` does not propagate read stream errors HOT 2
- [ BUG ] Examples / docs with sequential `write` without a callback are not ideal
- [Feature] Publish `typedoc` docs
- [question] Document node v20 memory usage improvement on perf test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sitemap.js.