Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve robots.txt based on doNotCrawl in Strapi export (RPB-43) #401

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/controllers/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import modules.IndexComponent;
import play.Environment;
import play.Logger;
import play.cache.Cached;
import play.libs.Json;
import play.libs.ws.WSBodyReadables;
import play.libs.ws.WSBodyWritables;
Expand Down Expand Up @@ -735,4 +736,14 @@ private static String findText(JsonNode info, String field) {
return node != null ? node.get("value").asText().replace("\n", " ").trim() : "";
}

@Cached(key = "robots", duration = 24 * 60 * 60) // One day
public Result robots() throws IOException {
return ok("User-agent: *\nDisallow: /"
+ Files.readAllLines(Paths.get("conf/rppd-export.jsonl")).stream()
.filter(line -> line.contains("doNotCrawl\":true"))
.map(line -> line.replaceAll(".*gndIdentifier\":\"(.+?)\".*", "$1")
.replaceAll("Keine GND-Ansetzung für ", ""))
.collect(Collectors.joining("\nDisallow: /")));
}

}
2 changes: 2 additions & 0 deletions app/modules/IndexComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import controllers.HomeController;
import net.sf.ehcache.CacheManager;
import play.Logger;
import play.inject.ApplicationLifecycle;

Expand Down Expand Up @@ -74,6 +75,7 @@ public ElasticsearchServer(ApplicationLifecycle lifecycle) {
});
lifecycle.addStopHook(() -> {
client.close();
CacheManager.getInstance().shutdown();
return null;
});
}
Expand Down
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ libraryDependencies += guice

libraryDependencies += ws

libraryDependencies += ehcache

libraryDependencies += "com.github.jsonld-java" % "jsonld-java" % "0.12.0"

libraryDependencies += "javax.mail" % "mail" % "1.4.1"
Expand Down
2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ GET /advanced controllers.HomeController.advanced()

GET /cgi-bin/wwwalleg/:name.pl controllers.HomeController.authorityPl(name, db ?= "rnam", index: Int ?= 1, zeilen: Int ?= 1, s1)

GET /robots.txt controllers.HomeController.robots()

GET /:id.:format controllers.HomeController.authorityDotFormat(id, format)

GET /:id controllers.HomeController.authority(id, format ?= null)
Expand Down
Loading