Skip to content

Commit

Permalink
Allow 'type' attribute on mobile element
Browse files Browse the repository at this point in the history
  • Loading branch information
zedix committed Oct 9, 2018
1 parent 03d849e commit 0ef3823
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/sitemap-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ class SitemapItem {
} else if (this[p] && p === 'androidLink') {
this.url.element('xhtml:link', {rel: 'alternate', href: this[p]})
} else if (this[p] && p === 'mobile') {
this.url.element('mobile:mobile')
const mobileitem = this.url.element('mobile:mobile')
if (typeof this[p] === 'string') {
mobileitem.att('type', this[p])
}
} else if (p === 'priority' && (this[p] >= 0.0 && this[p] <= 1.0)) {
this.url.element(p, parseFloat(this[p]).toFixed(1))
} else if (this[p] && p === 'ampLink') {
Expand Down
14 changes: 14 additions & 0 deletions tests/sitemap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ describe('sitemapItem', () => {
'</url>')
})

it('mobile with type', () => {
const url = 'http://ya.ru'
const smi = new sm.SitemapItem({
'url': url,
'mobile': 'pc,mobile'
})

expect(smi.toString()).toBe(
'<url>' +
xmlLoc +
'<mobile:mobile type="pc,mobile"/>' +
'</url>')
});

it('lastmodISO', () => {
const url = 'http://ya.ru'
const smi = new sm.SitemapItem({
Expand Down

0 comments on commit 0ef3823

Please sign in to comment.