2016-12-06 59 views
0

我使用以下npm包sitemap。它可以像基本的sitemap.xml一樣按預期工作。但是,Sitemaps索引的文檔似乎不完整。我已經使用下面的代碼片段...如何在Nodejs中創建和使用Sitemap索引?

var sm = require('sitemap') 
    , smi = sm.createSitemapIndex({ 
     cacheTime: 600000, 
     hostname: 'http://localhost:2000', 
     sitemapName: 'sm-test', 
     sitemapSize: 1, 
     targetFolder: require('os').tmpdir(), 
     urls: ['http://ya.ru', 'http://ya2.ru'] 
     // optional: 
     // callback: function(err, result) {} 
    }); 

我不知道如何測試站點地圖索引。請指教。

回答

0

隨着sitemap指數,你會看到一些配置:

targetFolder:>>這將節省的.xml文件到這裏

所以,當你運行代碼

var sm = require('sitemap') 
    , smi = sm.createSitemapIndex({ 
     cacheTime: 600000, 
     hostname: 'http://localhost:2000', 
     sitemapName: 'sm-test', 
     sitemapSize: 1, 
     targetFolder: require('os').tmpdir(), 
     urls: ['http://ya.ru', 'http://ya2.ru'] 
     // optional: 
     // callback: function(err, result) {} 
    }); 

文件sm-test-index.xml將在targetFolder中創建(Ex窗口: 用戶/應用程序數據/本地/ Temp)

希望它能幫助你。

感謝。

查看更多:網頁/ lib目錄/封裝sitemap.js

0

如果你希望他們添加到網站地圖索引Sitemap中的網址列表我 - 我和使用buildSitemapIndex

var sitemap = sm.buildSitemapIndex({ 
     urls: ['http://example.com/sitemap1.xml','http://example.com/sitemap.xml'] 
    }); 

並將其寫入站點地圖索引文件。

fs.writeFileSync("./sitemapindex.xml", sitemap.toString());