Class HtmlToApproximateMarkdownServicePlugin

    • Field Detail

      • allowedResourceTypePattern

        protected Pattern allowedResourceTypePattern
      • deniedResourceTypePattern

        protected Pattern deniedResourceTypePattern
      • blacklistedResourceType

        protected Map<String,​Long> blacklistedResourceType
        ResourceTypes we ignore since their rendering uses unsupported methods. Blacklisting for only 1h since there might be a deployment in the meantime. Maps the resource type to the time (ms) until it is blacklisted.
      • blacklistedResourceTypeCleanupTime

        protected volatile Long blacklistedResourceTypeCleanupTime
    • Constructor Detail

      • HtmlToApproximateMarkdownServicePlugin

        public HtmlToApproximateMarkdownServicePlugin()
    • Method Detail

      • cleanupBlacklist

        protected void cleanupBlacklist()
      • getImageUrl

        @Nullable
        public @Nullable String getImageUrl​(@Nullable
                                            @Nullable org.apache.sling.api.resource.Resource imageResource)
        Description copied from interface: ApproximateMarkdownServicePlugin
        Retrieves the imageURL in a way useable for ChatGPT - usually data:image/jpeg;base64,{base64_image} If the plugin cannot handle this resource, it should return null.
        Specified by:
        getImageUrl in interface ApproximateMarkdownServicePlugin
      • isBecauseOfUnsupportedOperation

        protected boolean isBecauseOfUnsupportedOperation​(Throwable e)
      • isIgnoredNode

        protected boolean isIgnoredNode​(@Nonnull
                                        org.apache.sling.api.resource.Resource resource)
        We start with depth 3 since the higher nodes often contain headers, navigation and such that don't help for ChatGPT.
      • renderedAsHTML

        protected String renderedAsHTML​(org.apache.sling.api.resource.Resource resource,
                                        org.apache.sling.api.SlingHttpServletRequest request,
                                        org.apache.sling.api.SlingHttpServletResponse response)
                                 throws javax.servlet.ServletException,
                                        IOException
        We render the resource into a mock response and capture and return the generated HTML. The response is wrapped so that the real response cannot be modified. We don't do that for the request, because that would be more complicated and probably not needed.
        Throws:
        javax.servlet.ServletException
        IOException
      • deactivate

        protected void deactivate()