~aprates/gempress

gempress/src/configure.c -rw-r--r-- 4.1 KiB
fc494358Antonio Prates Fix html lang bug 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// GemPress Wizard Helper, using Sugar-C
// 2021, by Antonio Prates <hello@aprates.dev>

#include <sugar.h>

void createFirstPost(string path, string date, string title, string author) {
  string postFilename = join2s(date, "-my-first-post.gmi");
  string archive =
      join4s("# ", title, "\r\n\r\n## Capsule Archives\r\n\r\n",
             join5s("=> ", postFilename, " ", date, " My First Post\r\n"));
  writeFile(archive,
            join2s(path, "/contents/log/index.gmi")); // replace default
  string postContent = join5s("# My First Post\r\n", date, " | ", author,
                              "\r\n\r\n"
                              "Wow! I've just started my new gemlog :D\r\n");
  writeFile(postContent, join3s(path, "/contents/log/", postFilename));
}

void createHomeFile(string path, string title, string author) {
  string home = join5s("# ", title, "\r\nHi, my name is ", author,
                       " and welcome to my Gemini Capsule!\r\n\r\n"
                       "## Capsule Feed\r\nHere are my most recent posts:\r\n");
  writeFile(home, join2s(path, "/contents/index.gmi"));
}

void configure(string path, string date) {
  println("What is your name:");
  string author = readKeys();

  println("How would you like to name your capsule:");
  string title = readKeys();

  println("What is the capsule's url alone, as in gemini://<url>:");
  string url = readKeys();

  string remoteBaseUrl = join2s("gemini://", url);

  string srhtSendUrl = join3s("https://pages.sr.ht/publish/", url, "\"\n");

  println("What is your OAuth 2.0 sr.ht access token (optional):");
  string srhtToken = readKeys();

  string localBaseDir = join2s(path, "/contents");

  string templateDir = join2s(path, "/template");

  string _heading = "# COMMON PUBLISHING SETTINGS";

  string _title = "\n\n"
                  "# Capsule name\ntitle=\"";

  string _author = "\"\n\n"
                   "# Your name\nauthor=\"";

  string _remoteBaseUrl = "\"\n\n"
                          "# Your root url - Without final slash (/)\n"
                          "remoteBaseUrl=\"";

  string _localBaseDir =
      "\"\n\n"
      "# Contents folder full path - Without final slash (/)\n"
      "localBaseDir=\"";

  string _templateDir =
      "\"\n\n"
      "# Template folder full path - Without final slash (/)\n"
      "templateDir=\"";

  string _otherConfigs =
      "\"\n\n"
      "# Customize 'back to home' link appended to feed\n"
      "gmiLinkHome=\"=> / Capsule Home\"\n\n"
      "# Folder where posts are stored inside localBaseDir\n"
      "feedDir=\"log\"\n\n"
      "# Folder where posts are stored inside from page root (optional)\n"
      "#absoluteFeedDir=\"\"  # defaults to feedDir value\n\n"
      "# Maximum number of atom entries (optional)\n"
      "#maxAtomEntries=\"\"  # defaults to \"15\"\n\n"
      "# Language code meta, like \"en-US\" or \"pt-BR\" (optional)\n"
      "#langCode=\"en-US\"  # not set by default\n\n"
      "# Extra markup conversions, non-standard for gemini\n"
      "# horizontal rule (---) and inline code in backticks\n"
      "#extraMarkup=\"enabled\"  # not set by default\n\n"
      "# SOURCEHUT PAGES PUBLISHING SETTINGS (OPTIONAL)\n\n";

  string _srhtToken = "# OAuth 2.0 sr.ht personal access token\nsrhtToken=\"";

  string _srhtSendUrl = "\"\n\n"
                        "# Your sr.ht send url\nsrhtSendUrl=\"";

  string configStrings[16] = {
      _heading,     _title,         title,         _author,
      author,       _remoteBaseUrl, remoteBaseUrl, _localBaseDir,
      localBaseDir, _templateDir,   templateDir,   _otherConfigs,
      _srhtToken,   srhtToken,      _srhtSendUrl,  srhtSendUrl};
  string config = mkString(16, configStrings);

  println("Creating Capsule Archive and first post…");
  createFirstPost(path, date, title, author);
  println("Creating Capsule Home…");
  createHomeFile(path, title, author);
  println("Saving configuration file…");
  writeFile(config, join2s(path, "/capsule.conf"));
}

app({
  if (argc < 3) {
    println("configure: provide args: <capsulePath> YYYY-MM-DD");
  } else {
    configure(argv[1], argv[2]);
    println("Done");
  }
})