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

Converts norgesfilm-urls for new format #612

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Part of NDLA article-api
* Copyright (C) 2025 NDLA
*
* See LICENSE
*
*/

package no.ndla.articleapi.db.migration

import no.ndla.articleapi.db.HtmlMigration
import org.jsoup.nodes.Element

class V58__ConvertNorgesfilmUrls extends HtmlMigration {
override val convertVisualElement: Boolean = true
override def convertHtml(doc: Element, language: String): Element = {
doc
.select("ndlaembed[data-resource='iframe']")
.forEach(embed => {
val url = embed.attr("data-url")
if (url.contains("ndla.filmiundervisning.no/film/ndlafilm.aspx?")) {
embed.attr("data-url", url.replace("/ndlafilm.aspx?", "/")): Unit
}
})
doc
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Part of NDLA article-api
* Copyright (C) 2025 NDLA
*
* See LICENSE
*
*/

package no.ndla.articleapi.db.migration

import no.ndla.articleapi.{TestEnvironment, UnitSuite}

class V58__ConvertNorgesfilmUrlsTest extends UnitSuite with TestEnvironment {
test("That norgesfilm urls looses ndlafilm.aspx") {
val migration = new V58__ConvertNorgesfilmUrls
val oldArticle =
"""<section><ndlaembed data-resource="iframe" data-type="iframe" data-url="https://ndla.filmiundervisning.no/film/ndlafilm.aspx?filmId=13074" data-width="700" data-height="300"></ndlaembed></section>"""
val newArticle =
"""<section><ndlaembed data-resource="iframe" data-type="iframe" data-url="https://ndla.filmiundervisning.no/film/filmId=13074" data-width="700" data-height="300"></ndlaembed></section>"""

migration.convertContent(oldArticle, "nb") should be(newArticle)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Part of NDLA draft-api
* Copyright (C) 2025 NDLA
*
* See LICENSE
*
*/

package no.ndla.draftapi.db.migration

import no.ndla.draftapi.db.HtmlMigration
import org.jsoup.nodes.Element

class V69__ConvertNorgesfilmUrls extends HtmlMigration {
override val convertVisualElement: Boolean = true
override def convertHtml(doc: Element, language: String): Element = {
doc
.select("ndlaembed[data-resource='iframe']")
.forEach(embed => {
val url = embed.attr("data-url")
if (url.contains("ndla.filmiundervisning.no/film/ndlafilm.aspx?")) {
embed.attr("data-url", url.replace("/ndlafilm.aspx?", "/")): Unit
}
})
doc
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Part of NDLA draft-api
* Copyright (C) 2025 NDLA
*
* See LICENSE
*
*/

package no.ndla.draftapi.db.migration

import no.ndla.draftapi.{TestEnvironment, UnitSuite}

class V69__ConvertNorgesfilmUrlsTest extends UnitSuite with TestEnvironment {
test("That norgesfilm urls looses ndlafilm.aspx") {
val migration = new V69__ConvertNorgesfilmUrls
val oldArticle =
"""<section><ndlaembed data-resource="iframe" data-type="iframe" data-url="https://ndla.filmiundervisning.no/film/ndlafilm.aspx?filmId=13074" data-width="700" data-height="300"></ndlaembed></section>"""
val newArticle =
"""<section><ndlaembed data-resource="iframe" data-type="iframe" data-url="https://ndla.filmiundervisning.no/film/filmId=13074" data-width="700" data-height="300"></ndlaembed></section>"""

migration.convertContent(oldArticle, "nb") should be(newArticle)
}
}