Created
August 31, 2022 11:58
Using jSoup To Fix Post-Marriage Name Changes In ColdFusion 2021
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
/** | |
* I fix Carol's LinkedIn URLs and name (after her name change). | |
*/ | |
private void function cleanUpCarolLinks( required string content ) { | |
// The jSoup library allows us to parse, traverse, and mutate HTML on the | |
// ColdFusion server using a familiar, luxurious jQuery-inspired syntax. | |
var dom = jSoupJavaLoader | |
.create( "org.jsoup.Jsoup" ) | |
.parse( content ) | |
.body() | |
; | |
// Find all the embedded anchor tags in the content that currently point to | |
// Carol's old LinkedIn profile (using a partial match on the LinkedIn slug in | |
// order to make the selector a tiny bit more flexible). | |
for ( var node in dom.select( "a[href*='carol-hamilton-5a869257']" ) ) { | |
// Update the link to point to her new LinkedIn profile. | |
node.attr( "href", "https://www.linkedin.com/in/carol-weiler-5a869257/" ); | |
// This is likely not going to be true in all cases; but, in many cases, the | |
// link to Carol's LinkedIn profile is preceded by her name (such as in the | |
// list of co-hosts on the Working Code podcast). In such a scenario, let's | |
// also try to back-up in the DOM tree and update her name as well. | |
var labelNodes = node | |
.parent() | |
.select( "strong:contains(Carol Hamilton)" ) | |
; | |
if ( labelNodes.len() ) { | |
labelNodes[ 1 ].text( "Carol Weiler" ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment