Last active
November 5, 2020 03:47
-
-
Save jossiey/a72111ede8abe3f1d3c7ba84ab1c4935 to your computer and use it in GitHub Desktop.
modify project LinkChecker-CmdLC to check links in Telescope posts
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
- public void checkWebsite(String link, int[] badLink) throws MalformedURLException { | |
+ public void checkWebsite(String link, int[] badLink) throws MalformedURLException { | |
+ | |
String content = argUrl(link); | |
//save the urls from the file, avoiding duplication | |
HashSet<String> links = new HashSet<String> (); | |
- //regular expression | |
- String urlRegex = "(https?)://[-a-zA-Z0-9+&@#/%?=~_|,!:.;]*[-a-zA-Z0-9+@#/%=&_|]"; | |
- Pattern pattern = Pattern.compile(urlRegex); | |
- Matcher matcher = pattern.matcher(content); | |
+ //check with local Telescope Server | |
+ String localServer = "http://localhost:3000/posts"; | |
+ | |
+ if(link.equals(localServer)) { | |
+ | |
+ String[] json = content.split("\"}"); | |
+ | |
+ for(String s:json) { | |
- while(matcher.find()) { | |
- links.add(matcher.group()); | |
+ if(s.indexOf("/", 1) > 0) { | |
+ String temp = "http://localhost:3000" + s.substring(s.indexOf("/")); | |
+ links.add(temp); | |
+ } | |
+ } | |
+ } | |
+ else { | |
+ | |
+ //regular expression | |
+ String urlRegex = "(https?)://[-a-zA-Z0-9+&@#/%?=~_|,!:.;]*[-a-zA-Z0-9+@#/%=&_|]"; | |
+ Pattern pattern = Pattern.compile(urlRegex); | |
+ Matcher matcher = pattern.matcher(content); | |
+ | |
+ while(matcher.find()) { | |
+ links.add(matcher.group()); | |
+ } | |
} | |
for(String url:links) { | |
urlTest(url, badLink); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment