From 1bc3cbde419a7b972109d71e65911728aaad81ee Mon Sep 17 00:00:00 2001 From: Justin York Date: Tue, 14 Dec 2021 14:45:38 -0600 Subject: [PATCH] v2.4.3 - fix #44, FamilySearch changed url params --- package.json | 2 +- src/sites/familysearch.js | 40 +++++++++++++++++++------------------- test/sites/familysearch.js | 8 ++++---- test/tester.js | 10 +++++++++- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index d925e9e..793c153 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gensearch", - "version": "2.4.2", + "version": "2.4.3", "description": "Generate search links for genealogy websites", "repository": { "type": "git", diff --git a/src/sites/familysearch.js b/src/sites/familysearch.js index 437180d..2847b7f 100644 --- a/src/sites/familysearch.js +++ b/src/sites/familysearch.js @@ -10,23 +10,23 @@ module.exports = function(config, data){ config = utils.defaults(config, defaultConfig); - var fsURL = 'https://www.familysearch.org/search/record/results?count=20'; + var fsURL = 'https://www.familysearch.org/search/record/results?'; var query = ''; // Simple mappings from the person data object to fs params // These don't need any special processing var simpleMappings = [ - ['givenname', 'givenName'], - ['surname', 'familyName'], - ['birth_place', 'birthPlace'], - ['death_place', 'deathPlace'], - ['father_givenname', 'fatherGivenName'], - ['father_surname', 'fatherFamilyName'], - ['mother_givenname', 'motherGivenName'], - ['mother_surname', 'motherFamilyName'], - ['spouse_givenname', 'spouseGivenName'], - ['spouse_surname', 'spouseFamilyName'], - ['marriage_place', 'marriagePlace'] + ['q.givenName', 'givenName'], + ['q.surname', 'familyName'], + ['q.birthLikePlace', 'birthPlace'], + ['q.deathLikePlace', 'deathPlace'], + ['q.fatherGivenName', 'fatherGivenName'], + ['q.fatherSurname', 'fatherFamilyName'], + ['q.motherGivenName', 'motherGivenName'], + ['q.motherSurname', 'motherFamilyName'], + ['q.spouseGivenName', 'spouseGivenName'], + ['q.spouseSurname', 'spouseFamilyName'], + ['q.marriageLikePlace', 'marriagePlace'] ]; utils.each(simpleMappings, function(map) { if( data[map[1]] ) { @@ -38,8 +38,8 @@ module.exports = function(config, data){ if(data.birthDate){ var birthYear = utils.getYearInt(data.birthDate); if( birthYear ) { - query = utils.addQueryParam(query, 'birth_year_from', birthYear - config.birthRange); - query = utils.addQueryParam(query, 'birth_year_to', birthYear + config.birthRange) + query = utils.addQueryParam(query, 'q.birthLikeDate.from', birthYear - config.birthRange); + query = utils.addQueryParam(query, 'q.birthLikeDate.to', birthYear + config.birthRange) } } @@ -47,8 +47,8 @@ module.exports = function(config, data){ if(data.deathDate){ var deathYear = utils.getYearInt(data.deathDate); if( deathYear ) { - query = utils.addQueryParam(query, 'death_year_from', deathYear - config.deathRange); - query = utils.addQueryParam(query, 'death_year_to', deathYear + config.deathRange); + query = utils.addQueryParam(query, 'q.deathLikeDate.from', deathYear - config.deathRange); + query = utils.addQueryParam(query, 'q.deathLikeDate.to', deathYear + config.deathRange); } } @@ -56,15 +56,15 @@ module.exports = function(config, data){ if(data.marriageDate){ var marriageYear = utils.getYearInt(data.marriageDate); if( marriageYear ) { - query = utils.addQueryParam(query, 'marriage_year_from', marriageYear - config.marriageRange); - query = utils.addQueryParam(query, 'marriage_year_to', marriageYear + config.marriageRange); + query = utils.addQueryParam(query, 'q.marriageLikeDate.from', marriageYear - config.marriageRange); + query = utils.addQueryParam(query, 'q.marriageLikeDate.to', marriageYear + config.marriageRange); } } if(config.collectionId){ - query = utils.addQueryParam(query, 'collection_id', config.collectionId); + query = utils.addQueryParam(query, 'f.collectionId', config.collectionId); } - return fsURL + query; + return fsURL + query.replace('&', ''); }; diff --git a/test/sites/familysearch.js b/test/sites/familysearch.js index 58aed1e..0f3ba36 100644 --- a/test/sites/familysearch.js +++ b/test/sites/familysearch.js @@ -3,15 +3,15 @@ var test = require('../tester.js')('familysearch'); describe('familysearch', function(){ it('1', function(){ - test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark'); + test(test.data[0], 'https://www.familysearch.org/search/record/results?q.givenName=Joe%20William&q.surname=Clark'); }); it('2', function(){ - test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&birth_place=Texas&death_place=Springfield%2C%20Illinois&father_givenname=Dale&father_surname=Clark&mother_givenname=Susan&mother_surname=Anthony&spouse_givenname=Jennifer&spouse_surname=Thomas&marriage_place=St%20Louis%2C%20MO&birth_year_from=1833&birth_year_to=1837&death_year_from=1887&death_year_to=1891&marriage_year_from=1856&marriage_year_to=1860'); + test(test.data[1], 'https://www.familysearch.org/search/record/results?q.birthLikeDate.from=1833&q.birthLikeDate.to=1837&q.birthLikePlace=Texas&q.deathLikeDate.from=1887&q.deathLikeDate.to=1891&q.deathLikePlace=Springfield%2C%20Illinois&q.fatherGivenName=Dale&q.fatherSurname=Clark&q.givenName=Joe%20William&q.marriageLikeDate.from=1856&q.marriageLikeDate.to=1860&q.marriageLikePlace=St%20Louis%2C%20MO&q.motherGivenName=Susan&q.motherSurname=Anthony&q.spouseGivenName=Jennifer&q.spouseSurname=Thomas&q.surname=Clark'); }); it('config', function(){ - test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&birth_place=Texas&death_place=Springfield%2C%20Illinois&father_givenname=Dale&father_surname=Clark&mother_givenname=Susan&mother_surname=Anthony&spouse_givenname=Jennifer&spouse_surname=Thomas&marriage_place=St%20Louis%2C%20MO&birth_year_from=1832&birth_year_to=1838&death_year_from=1885&death_year_to=1893&marriage_year_from=1853&marriage_year_to=1863', { + test(test.data[1], 'https://www.familysearch.org/search/record/results?q.birthLikeDate.from=1832&q.birthLikeDate.to=1838&q.birthLikePlace=Texas&q.deathLikeDate.from=1885&q.deathLikeDate.to=1893&q.deathLikePlace=Springfield%2C%20Illinois&q.fatherGivenName=Dale&q.fatherSurname=Clark&q.givenName=Joe%20William&q.marriageLikeDate.from=1853&q.marriageLikeDate.to=1863&q.marriageLikePlace=St%20Louis%2C%20MO&q.motherGivenName=Susan&q.motherSurname=Anthony&q.spouseGivenName=Jennifer&q.spouseSurname=Thomas&q.surname=Clark', { birthRange: 3, deathRange: 4, marriageRange: 5 @@ -19,7 +19,7 @@ describe('familysearch', function(){ }); it('collection', function(){ - test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&collection_id=1473014', { + test(test.data[0], 'https://www.familysearch.org/search/record/results?q.givenName=Joe%20William&q.surname=Clark&f.collectionId=1473014', { collectionId: 1473014 }); }); diff --git a/test/tester.js b/test/tester.js index 49ef10e..49585f5 100644 --- a/test/tester.js +++ b/test/tester.js @@ -4,7 +4,15 @@ var assert = require('assert'), module.exports = function(site){ var tester = function(data, url, opts){ - assert.equal(search(site, data, opts), url); + // Parse URLs so that we can compare query params without requiring them to be in the same order + const searchUrl = new URL(search(site, data, opts)); + const expectedUrl = new URL(url); + // Compare origin and path + assert.equal(`${searchUrl.origin}${searchUrl.pathname}`, `${expectedUrl.origin}${expectedUrl.pathname}`); + // Compare query params + searchUrl.searchParams.sort(); + expectedUrl.searchParams.sort() + assert.equal(searchUrl.searchParams.toString(), expectedUrl.searchParams.toString()); }; tester.data = data; return tester;