Skip to content

Instantly share code, notes, and snippets.

@jossiey
Last active November 5, 2020 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jossiey/a72111ede8abe3f1d3c7ba84ab1c4935 to your computer and use it in GitHub Desktop.
Save jossiey/a72111ede8abe3f1d3c7ba84ab1c4935 to your computer and use it in GitHub Desktop.
modify project LinkChecker-CmdLC to check links in Telescope posts
- 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