Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treatment links with *.oga file #1763

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/util/rewriteUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function rewriteUrlNoArticleCheck(articleId: string, mw: MediaWiki, dump: Dump,
lat = parts[4]
lon = parts[5]
} else if (rel === 'mw:MediaLink') {
const shouldScrape = (href.includes('.pdf') && !dump.nopdf) || (href.includes('.ogg') && !dump.nopic && !dump.novid && !dump.nodet)
const shouldScrape = (href.includes('.pdf') && !dump.nopdf) || ((href.includes('.ogg') || href.includes('.oga')) && !dump.nopic && !dump.novid && !dump.nodet)

if (shouldScrape) {
try {
Expand All @@ -110,6 +110,8 @@ function rewriteUrlNoArticleCheck(articleId: string, mw: MediaWiki, dump: Dump,
logger.warn('Error parsing url:', err)
DU.deleteNode(linkNode)
}
} else if (href.includes('.ogg') || href.includes('.oga')) {
linkNode.outerHTML = linkNode.innerHTML
}
return null
}
Expand Down
9 changes: 9 additions & 0 deletions test/unit/urlRewriting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ describe('Styles', () => {
const $resourceLink = makeLink($doc, '//upload.wikimedia.org/wikipedia/commons/c/c6/De-Z%C3%BCrich.ogg', '', 'De-Z%C3%BCrich.ogg', 'Zurich', {
resource: './Media:De-Zürich.ogg',
})
const $ogaResourceLink = makeLink($doc, '//upload.wikimedia.org/wikipedia/commons/7/7e/Fr-Laissez-faire.oga', '', 'Fr-Laissez-faire.oga', 'listen', {
resource: './Media:Fr-Laissez-faire.oga',
})

await rewriteUrl(complexParentArticleId, redisStore, mw, dump, $geo)
// Geo is still a link
Expand Down Expand Up @@ -122,6 +125,12 @@ describe('Styles', () => {
expect($resourceLink.nodeName).toEqual('A')
// resourceLink has been re-written
expect($resourceLink.getAttribute('href')).toEqual('../../I/De-Z%C3%BCrich.ogg')

await rewriteUrl(complexParentArticleId, redisStore, mw, dump, $ogaResourceLink)
// ogaResourceLink is still a link
expect($ogaResourceLink.nodeName).toEqual('A')
// ogaResourceLink has been re-written
expect($ogaResourceLink.getAttribute('href')).toEqual('../../I/Fr-Laissez-faire.oga')
})

test('e2e url rewriting', async () => {
Expand Down