diff --git a/DESCRIPTION b/DESCRIPTION index ac3e51ac..c003cdd6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sandpaper Title: Create and Curate Carpentries Lessons -Version: 0.16.1.9000 +Version: 0.16.2 Authors@R: c( person(given = "Zhian N.", family = "Kamvar", diff --git a/NEWS.md b/NEWS.md index 45d3ef46..c9c79de6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# sandpaper 0.16.1.9000 (unreleased) +# sandpaper 0.16.2 (2023-12-19) + +## MISC + +* JSON metadata now contains the `inLanguage` key. ## DOCUMENTATION diff --git a/R/utils-metadata.R b/R/utils-metadata.R index bd50e7cf..a941c4b9 100644 --- a/R/utils-metadata.R +++ b/R/utils-metadata.R @@ -13,6 +13,7 @@ fill_metadata_template <- function(meta) { if (endsWith(local_meta$url, "/")) { local_meta$url <- paste0(local_meta$url, "index.html") } + local_meta$lang <- sub("_", "-", local_meta$lang %||% "en") title <- local_meta$pagetitle if (grepl("<", title, fixed = TRUE)) { local_meta$pagetitle <- xml2::xml_text(xml2::read_html(title)) diff --git a/inst/templates/metadata-template.txt b/inst/templates/metadata-template.txt index 7aeee275..d205d566 100644 --- a/inst/templates/metadata-template.txt +++ b/inst/templates/metadata-template.txt @@ -3,6 +3,7 @@ "@context": "https://schema.org", "@type": "TrainingMaterial", "@id": "<% url %>", + "inLanguage": "<% lang %>", "dct:conformsTo": "https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE", "description": "<% desc %><% ^desc %>A Carpentries Lesson teaching foundational data and coding skills to researchers worldwide<% /desc %>", "keywords": "<% keywords %><% ^keywords %>software,data,lesson,The Carpentries<% /keywords %>", diff --git a/tests/testthat/_snaps/utils-metadata.md b/tests/testthat/_snaps/utils-metadata.md index 19853540..4ae58569 100644 --- a/tests/testthat/_snaps/utils-metadata.md +++ b/tests/testthat/_snaps/utils-metadata.md @@ -1,4 +1,4 @@ # metadata can be initialised with custom items added - "{\n \"@context\": \"https://schema.org\",\n \"@type\": \"TrainingMaterial\",\n \"@id\": \"https://zkamvar.github.io/lesson-example/vern.html\",\n \"dct:conformsTo\": \"https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE\",\n \"description\": \"A Carpentries Lesson teaching foundational data and coding skills to researchers worldwide\",\n \"keywords\": \"software, data, lesson, The Carpentries\",\n \"name\": \"The Importance of Being Ernest Scared Stupid\",\n \"creativeWorkStatus\": \"active\",\n \"url\": \"https://zkamvar.github.io/lesson-example/vern.html\",\n \"identifier\": \"https://zkamvar.github.io/lesson-example/vern.html\",\n \"dateCreated\": \"2022-02-01\",\n \"dateModified\": \"2022-02-08\",\n \"datePublished\": \"2022-02-09\"\n}\n" + "{\n \"@context\": \"https://schema.org\",\n \"@type\": \"TrainingMaterial\",\n \"@id\": \"https://zkamvar.github.io/lesson-example/vern.html\",\n \"inLanguage\": \"en\",\n \"dct:conformsTo\": \"https://bioschemas.org/profiles/TrainingMaterial/1.0-RELEASE\",\n \"description\": \"A Carpentries Lesson teaching foundational data and coding skills to researchers worldwide\",\n \"keywords\": \"software, data, lesson, The Carpentries\",\n \"name\": \"The Importance of Being Ernest Scared Stupid\",\n \"creativeWorkStatus\": \"active\",\n \"url\": \"https://zkamvar.github.io/lesson-example/vern.html\",\n \"identifier\": \"https://zkamvar.github.io/lesson-example/vern.html\",\n \"dateCreated\": \"2022-02-01\",\n \"dateModified\": \"2022-02-08\",\n \"datePublished\": \"2022-02-09\"\n}\n" diff --git a/tests/testthat/test-utils-metadata.R b/tests/testthat/test-utils-metadata.R index 783571f7..6831c1ea 100644 --- a/tests/testthat/test-utils-metadata.R +++ b/tests/testthat/test-utils-metadata.R @@ -18,16 +18,27 @@ test_that("metadata can be initialised with custom items added ", { on.exit(this_metadata$clear()) # metadata has same values as config expect_equal(this_metadata$get()[["carpentry"]], "incubator") - met <- create_metadata_jsonld(res, + met <- create_metadata_jsonld(res, date = list(created = "2022-02-01", modified = "2022-02-08", published = "2022-02-09"), pagetitle = "The Importance of Being Ernest Scared Stupid", url = "https://zkamvar.github.io/lesson-example/vern.html" ) expect_type(met, "character") expect_match(met, "Ernest Scared Stupid") + expect_match(met, "\"inLanguage\": \"en\"", fixed = TRUE) expect_length(met, 1L) skip_on_os("windows") # dang carriage returns expect_snapshot_value(met) + + met <- create_metadata_jsonld(res, + pagetitle = "The Importance of Being Ernest Scared Stupid", + url = "https://zkamvar.github.io/lesson-example/vern.html", + lang = "es_AR" + ) + expect_type(met, "character") + expect_match(met, "Ernest Scared Stupid") + expect_match(met, "\"inLanguage\": \"es-AR\"", fixed = TRUE) + expect_length(met, 1L) })