~aprates/gempress

7cb0bffb48f2674c6c24a04310b0fc855d326214 — Antonio Prates 7 months ago ce87d08
Use date from description on atom feed

Trying to comply to Gemini simple feed specification:
gemini://gemini.circumlunar.space/docs/companion/subscription.gmi
2 files changed, 9 insertions(+), 8 deletions(-)

M README.md
M src/atom.c
M README.md => README.md +1 -0
@@ 99,6 99,7 @@ contents
    ├── index.gmi  # Archive (links to the posts)
    └── YYYY-DD-MM-post-1.gmi
```
See the [Gemini simple feed specification](gemini://gemini.circumlunar.space/docs/companion/subscription.gmi) for `/log/index.gmi` structure reference.
Also, your configured `templateDir` should be of the following structure:
```
template

M src/atom.c => src/atom.c +8 -8
@@ 1,5 1,7 @@
// GemPress feed-to-atom utility, using Sugar-C
// 2021, by Antonio Prates <antonioprates at gmail dot com>
// Trying to comply to Gemini simple feed specification:
// gemini://gemini.circumlunar.space/docs/companion/subscription.gmi

/* USAGE NOTES:



@@ 7,7 9,7 @@ This is a bit of a primitive tool and it expects a few things to work!

1. Gemini file as argument, containing the list of links (=>), like:

   => /log/YYYY-MM-DD-some-title.gmi Heading Of The Post
   => some-title.gmi YYYY-MM-DD Heading Of The Post

   Make sure that the URLs contain the date, as date is extracted from there.



@@ 130,19 132,16 @@ string toAtomEntry(string line) {
  if (startsWith(line, "=&gt;")) {          // => link (escaped)
    stringList words = splitSep(line, ' '); // tokenize the link
    number wordCount = listCount(words);    // count our tokens
    if (wordCount > 1) {                    // fail-safe for missing link
    if (wordCount > 3) {                    //must have: => url date desc.
      string url = words[1];                // get url
      // using the initial part of the filename as the date YYYY-MM-DD
      stringList path = splitSep(url, '/');
      number pathMemberCount = listCount(path);
      string date = pathMemberCount > 1 ? path[pathMemberCount - 1] : path[0];
      // using the initial part of the description as the date YYYY-MM-DD
      string description = joinSep(listCount(&words[2]), &words[2], ' ') ;
      string date = splitSep(description, ' ')[0];
      if (isDigit(date[0]) && isDigit(date[1]) && isDigit(date[2]) &&
          isDigit(date[3]) && date[4] == '-' && isDigit(date[5]) &&
          isDigit(date[6]) && date[7] == '-' && isDigit(date[9]) &&
          isDigit(date[9])) {
        date[10] = STR_END;  // trim to 10 chars
        string description = // join the rest as description OR use url as desc.
            wordCount > 2 ? joinSep(listCount(&words[2]), &words[2], ' ') : url;
        description = replaceWord(description, date, "");
        if (startsWith(description, " - "))
          description = &description[3];


@@ 153,6 152,7 @@ string toAtomEntry(string line) {
          lastUpdated = updated;
        else if (strcmp(updated, lastUpdated) > 0)
          lastUpdated = updated;
        url = startsWith(url, "/") ? url : join3s("/", feedDir, url);
        url = maybeToHttps(join2s(remoteBaseUrl, url));
        return join3s(
            join3s("  <entry>\n    <id>", url, "</id>\n"),