Skip to content

Commit 6b00c65

Browse files
committed
Update Plausible script
1 parent 8142d20 commit 6b00c65

File tree

241 files changed

+56960
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+56960
-0
lines changed
2.36 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as $envoy from "../envoy/envoy.mjs";
2+
import * as $io from "../gleam_stdlib/gleam/io.mjs";
3+
import * as $result from "../gleam_stdlib/gleam/result.mjs";
4+
import * as $string from "../gleam_stdlib/gleam/string.mjs";
5+
import * as $simplifile from "../simplifile/simplifile.mjs";
6+
import { Ok } from "./gleam.mjs";
7+
8+
function generate_module(search_url, hexdocs_url, hexpm_url) {
9+
return ((((("/// Configuration constants generated from environment variables at build time.\n/// Do not edit this file directly - it is generated by `cd config && gleam run -m config`.\n///\n/// To regenerate with custom URLs, set environment variables before running:\n/// cd config && SEARCH_URL=... HEXDOCS_URL=... HEXPM_URL=... gleam run -m config\n\n/// Get the search API URL\npub fn search_url() -> String {\n \"" + search_url) + "\"\n}\n\n/// Get the hexdocs base URL\npub fn hexdocs_url() -> String {\n \"") + hexdocs_url) + "\"\n}\n\n/// Get the hex.pm API URL\npub fn hexpm_url() -> String {\n \"") + hexpm_url) + "\"\n}\n";
10+
}
11+
12+
function print_config(key, value) {
13+
let _block;
14+
if (key === "SEARCH_URL") {
15+
_block = "https://search.hexdocs.pm";
16+
} else if (key === "HEXDOCS_URL") {
17+
_block = "https://hexdocs.pm";
18+
} else if (key === "HEXPM_URL") {
19+
_block = "https://hex.pm";
20+
} else {
21+
_block = "";
22+
}
23+
let default$ = _block;
24+
let _block$1;
25+
let $ = value === default$;
26+
if ($) {
27+
_block$1 = "(default)";
28+
} else {
29+
_block$1 = "(from env)";
30+
}
31+
let source = _block$1;
32+
return $io.println(((((" " + key) + " = ") + value) + " ") + source);
33+
}
34+
35+
/**
36+
* Generate the hexdocs/config module with URL constants from environment variables.
37+
*
38+
* Environment variables:
39+
* - SEARCH_URL: The search API endpoint (default: https://search.hexdocs.pm)
40+
* - HEXDOCS_URL: The hexdocs base URL (default: https://hexdocs.pm)
41+
* - HEXPM_URL: The hex.pm API URL (default: https://hex.pm)
42+
*/
43+
export function main() {
44+
$io.println("Generating hexdocs/config from environment variables...");
45+
$io.println("");
46+
let _block;
47+
let _pipe = $envoy.get("SEARCH_URL");
48+
_block = $result.unwrap(_pipe, "https://search.hexdocs.pm");
49+
let search_url = _block;
50+
let _block$1;
51+
let _pipe$1 = $envoy.get("HEXDOCS_URL");
52+
_block$1 = $result.unwrap(_pipe$1, "https://hexdocs.pm");
53+
let hexdocs_url = _block$1;
54+
let _block$2;
55+
let _pipe$2 = $envoy.get("HEXPM_URL");
56+
_block$2 = $result.unwrap(_pipe$2, "https://hex.pm");
57+
let hexpm_url = _block$2;
58+
$io.println("Configuration:");
59+
print_config("SEARCH_URL", search_url);
60+
print_config("HEXDOCS_URL", hexdocs_url);
61+
print_config("HEXPM_URL", hexpm_url);
62+
$io.println("");
63+
let content = generate_module(search_url, hexdocs_url, hexpm_url);
64+
let output_path = "../src/hexdocs/config.gleam";
65+
let $ = $simplifile.write(output_path, content);
66+
if ($ instanceof Ok) {
67+
return $io.println("✓ Successfully generated " + output_path);
68+
} else {
69+
let err = $[0];
70+
$io.println("✗ Failed to write config file:");
71+
return $io.println(" " + $string.inspect(err));
72+
}
73+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { main } from "./config.mjs";
2+
main();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "../prelude.mjs";
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { execSync } from 'child_process';
2+
3+
export function formatFile(path) {
4+
try {
5+
execSync(`gleam format ${path}`, { encoding: 'utf-8', stdio: 'pipe' });
6+
return { ok: undefined };
7+
} catch (error) {
8+
return { error: error.message };
9+
}
10+
}
2.5 KB
Binary file not shown.
307 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-module(envoy).
2+
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
3+
4+
-export([get/1, set/2, unset/1, all/0]).
5+
6+
-file("/Users/louis/src/gleam/envoy/src/envoy.gleam", 17).
7+
-spec get(binary()) -> {ok, binary()} | {error, nil}.
8+
get(Name) ->
9+
envoy_ffi:get(Name).
10+
11+
-file("/Users/louis/src/gleam/envoy/src/envoy.gleam", 33).
12+
-spec set(binary(), binary()) -> nil.
13+
set(Name, Value) ->
14+
envoy_ffi:set(Name, Value).
15+
16+
-file("/Users/louis/src/gleam/envoy/src/envoy.gleam", 51).
17+
-spec unset(binary()) -> nil.
18+
unset(Name) ->
19+
envoy_ffi:unset(Name).
20+
21+
-file("/Users/louis/src/gleam/envoy/src/envoy.gleam", 57).
22+
-spec all() -> gleam@dict:dict(binary(), binary()).
23+
all() ->
24+
envoy_ffi:all().

0 commit comments

Comments
 (0)