Giter Club home page Giter Club logo

Comments (2)

jameslittle230 avatar jameslittle230 commented on August 23, 2024

Antora definitely looks like a project that would make sense for a Stork integration.

Being realistic - project-specific integrations take time, and I'll likely invest the next few chunks of time improving Stork itself, rather than building external integrations. If there are specific pain points you have integrating with Antora that I can address in the meantime, I can evaluate them separately, but unless this Github issue takes off, I likely won't get to this feature for a long time.

Thanks for the feature suggestion, though! I'm excited that you're liking Stork and am happy to help you keep working with it however I can.

James

from stork.

franchb avatar franchb commented on August 23, 2024

Hi!

I want to share my workaround for self-hosted Stork for Antora.

After Antora static HTML generation we could parse sitemap.xml, extract all .html files and document titles and generate .toml configuration for stork.

Here is my sample Python script:

#!/usr/bin/env python3

import re
from string import Template

toml = Template("""
[input]
base_directory = "."
url_prefix = "$prefix"
html_selector = "main.article"
stemming="English"
files = $files

[output]
displayed_results_count=10
excerpt_buffer=8
#exclude_html_selector="code"
excerpts_per_result=5
debug = false
""")


PREFIX = "<static env of dynamic from CI>"
ptn = re.compile("^\\s*<meta property=\"og:title\".*?content=\"(.*)\">$", re.UNICODE)


def build_node(s: str) -> dict:
    tail = s\
        .rstrip()\
        .removeprefix("<loc>" + PREFIX_BROKEN)\
        .removesuffix("</loc>")
    full = "_public/<YOUR_PROJECT>/1.0"+tail
    return {"path": full, "url": tail, "title": extract_title(full), "filetype": "HTML"}


def compile_toml() -> str:
    with open('_public/sitemap.xml') as sitemap_file:
        files = [
            build_node(line)
            for line in sitemap_file if line.startswith("<loc>")
        ]

    return toml.substitute(files=str(files).replace("': '", "' = '"), prefix=PREFIX)


def extract_title(filepath: str) -> str:
    with open(filepath) as html_file:
        for line in html_file:
            matches = re.search(ptn, line)
            if matches:
                return matches.group(1)
    return ""




if __name__ == "__main__":
    arg = compile_toml()
    with open("docs.toml", "w") as f:
        f.write(arg)

Next, run stork build --input docs.toml --output ./supplemental_ui/search_index.st.

Add stork to partials:

supplemental_ui/partials/footer-content.hbs

<script src="{{{uiRootPath}}}/js/stork.js"></script>
<script>
    stork.initialize("{{{uiRootPath}}}/stork.wasm")
    stork.register(
            "docs",
            "{{{uiRootPath}}}/search_index.st"
    );
</script>

Also I've made some patches to an Antora Default UI bundle:

Add stork.js to js/vendor/ folder:

src/partials/footer-scripts.hbs

<script src="{{{uiRootPath}}}/js/vendor/stork.js"></script>

Add search input:

src/partials/header-content.hbs

            <div class="stork-wrapper-flat">
              <input data-stork="docs" class="stork-input" />
              <div data-stork="docs-output" class="stork-output"></div>
            </div>

Add stork CSS:

@import url("stork-flat.css");

from stork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.