diff options
| -rw-r--r-- | src/cli/stasis_indexer/helpers.c | 59 | ||||
| -rw-r--r-- | src/cli/stasis_indexer/website.c | 59 | 
2 files changed, 63 insertions, 55 deletions
| diff --git a/src/cli/stasis_indexer/helpers.c b/src/cli/stasis_indexer/helpers.c index cfc1ed6..1c51e8d 100644 --- a/src/cli/stasis_indexer/helpers.c +++ b/src/cli/stasis_indexer/helpers.c @@ -79,6 +79,65 @@ int get_pandoc_version(size_t *result) {      return 0;  } +int pandoc_exec(const char *in_file, const char *out_file, const char *css_file, const char *title) { +    if (!find_program("pandoc")) { +        fprintf(stderr, "pandoc is not installed: unable to generate HTML indexes\n"); +        return 0; +    } + +    char pandoc_versioned_args[255] = {0}; +    size_t pandoc_version = 0; +    if (!get_pandoc_version(&pandoc_version)) { +        // < 2.19 +        if (pandoc_version < 0x02130000) { +            strcat(pandoc_versioned_args, "--self-contained "); +        } else { +            // >= 2.19 +            strcat(pandoc_versioned_args, "--embed-resources "); +        } + +        // >= 1.15.0.4 +        if (pandoc_version >= 0x010f0004) { +            strcat(pandoc_versioned_args, "--standalone "); +        } + +        // >= 1.10.0.1 +        if (pandoc_version >= 0x010a0001) { +            strcat(pandoc_versioned_args, "-f gfm+autolink_bare_uris "); +        } + +        // > 3.1.9 +        if (pandoc_version > 0x03010900) { +            strcat(pandoc_versioned_args, "-f gfm+alerts "); +        } +    } + +    // Converts a markdown file to html +    char cmd[STASIS_BUFSIZ] = {0}; +    strcpy(cmd, "pandoc "); +    strcat(cmd, pandoc_versioned_args); +    if (css_file && strlen(css_file)) { +        strcat(cmd, "--css "); +        strcat(cmd, css_file); +    } +    strcat(cmd, " "); +    strcat(cmd, "--metadata title=\""); +    strcat(cmd, title); +    strcat(cmd, "\" "); +    strcat(cmd, "-o "); +    strcat(cmd, out_file); +    strcat(cmd, " "); +    strcat(cmd, in_file); + +    if (globals.verbose) { +        puts(cmd); +    } + +    // This might be negative when killed by a signal. +    return system(cmd); +} + +  int micromamba_configure(const struct Delivery *ctx, struct MicromambaInfo *m) {      int status = 0;      char *micromamba_prefix = NULL; diff --git a/src/cli/stasis_indexer/website.c b/src/cli/stasis_indexer/website.c index c04b7f2..cf5f3c2 100644 --- a/src/cli/stasis_indexer/website.c +++ b/src/cli/stasis_indexer/website.c @@ -2,11 +2,6 @@  #include "website.h"  int indexer_make_website(const struct Delivery *ctx) { -    if (!find_program("pandoc")) { -        fprintf(stderr, "pandoc is not installed: unable to generate HTML indexes\n"); -        return 0; -    } -      char *css_filename = calloc(PATH_MAX, sizeof(*css_filename));      if (!css_filename) {          SYSERROR("unable to allocate string for CSS file path: %s", strerror(errno)); @@ -16,34 +11,6 @@ int indexer_make_website(const struct Delivery *ctx) {      sprintf(css_filename, "%s/%s", globals.sysconfdir, "stasis_pandoc.css");      const int have_css = access(css_filename, F_OK | R_OK) == 0; -    char pandoc_versioned_args[255] = {0}; -    size_t pandoc_version = 0; - -    if (!get_pandoc_version(&pandoc_version)) { -        // < 2.19 -        if (pandoc_version < 0x02130000) { -            strcat(pandoc_versioned_args, "--self-contained "); -        } else { -            // >= 2.19 -            strcat(pandoc_versioned_args, "--embed-resources "); -        } - -        // >= 1.15.0.4 -        if (pandoc_version >= 0x010f0004) { -            strcat(pandoc_versioned_args, "--standalone "); -        } - -        // >= 1.10.0.1 -        if (pandoc_version >= 0x010a0001) { -            strcat(pandoc_versioned_args, "-f gfm+autolink_bare_uris "); -        } - -        // > 3.1.9 -        if (pandoc_version > 0x03010900) { -            strcat(pandoc_versioned_args, "-f gfm+alerts "); -        } -    } -      struct StrList *dirs = strlist_init();      strlist_append(&dirs, ctx->storage.delivery_dir);      strlist_append(&dirs, ctx->storage.results_dir); @@ -71,29 +38,11 @@ int indexer_make_website(const struct Delivery *ctx) {              strcpy(fullpath_dest, fullpath_src);              gen_file_extension_str(fullpath_dest, ".html"); -            // Converts a markdown file to html -            strcpy(cmd, "pandoc "); -            strcat(cmd, pandoc_versioned_args); -            if (have_css) { -                strcat(cmd, "--css "); -                strcat(cmd, css_filename); -            } -            strcat(cmd, " "); -            strcat(cmd, "--metadata title=\"STASIS\" "); -            strcat(cmd, "-o "); -            strcat(cmd, fullpath_dest); -            strcat(cmd, " "); -            strcat(cmd, fullpath_src); -            if (globals.verbose) { -                puts(cmd); -            } -            // This might be negative when killed by a signal. -            // Otherwise, the return code is not critical to us. -            if (system(cmd) < 0) { -                guard_free(css_filename); -                guard_strlist_free(&dirs); -                return 1; +            // Convert markdown to html +            if (pandoc_exec(fullpath_src, fullpath_dest, have_css ? css_filename : NULL, "STASIS")) { +                msg(STASIS_MSG_L2 | STASIS_MSG_WARN, "Unable to convert %s\n", fullpath_src);              } +              if (file_replace_text(fullpath_dest, ".md", ".html", 0)) {                  // inform-only                  SYSERROR("%s: failed to rewrite *.md urls with *.html extension", fullpath_dest); | 
