Skip to content

Commit 27d5f97

Browse files
committed
fix #1
1 parent a50d5a0 commit 27d5f97

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
- uses: ./
1616
with:
1717
project-string: ${{ secrets.PROJECT_STRING }}
18+
base-url: https://your-website.com/docs/
1819
database: documentation.sqlite
1920
strip-astro-header: true
2021
strip-md-titles: true

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
uses: sqlitecloud/docsearch-action@v1
4343
with:
4444
project-string: ${{ secrets.PROJECT_STRING }}
45+
base-url: https://your-website.com/docs/
4546
path: path/to/your/docs
4647
database: my-docs-search
4748
```
@@ -50,11 +51,12 @@ jobs:
5051
4. Add the Project Connection String as a secret in your repository settings, named `PROJECT_STRING`.
5152
5. Create a database in your SQLite Cloud project and write its name in the `database` input of the action.
5253
6. Customize these inputs according to your needs.
53-
* if the `path` input isn't specified the workflow will search for every .md or .mdx file recursively from the root folder.
54-
* `strip-html`: Set this input to `true` if you want to remove the html elements.
55-
* `strip-jsx`: Set this input to `true` if you want to remove the jsx elements.
56-
* `strip-md-titles`: Set this input to `true` if you want to remove the markdown titles to avoid redundancy in the search.
57-
* `strip-astro-header`: Set this input to `true` if you want to remove the Astro header from every file.
54+
* The `base-url` represents the common part of your documentation URL.
55+
* If the `path` input is not specified, the workflow will recursively search for every .md or .mdx file starting from the root folder.
56+
* Set the `strip-html` input to `true` if you want to remove HTML elements.
57+
* Set the `strip-jsx` input to `true` if you want to remove JSX elements.
58+
* Set the `strip-md-titles` input to `true` if you want to remove markdown titles to avoid redundancy in the search.
59+
* Set the `strip-astro-header` input to `true` if you want to remove the Astro header from every file.
5860
7. Commit and push the workflow file to your repository.
5961

6062

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ inputs:
66
project-string:
77
description: The SQLite Cloud project connection string.
88
required: true
9+
base-url:
10+
description: Your website's documentation base url.
11+
required: true
912
database:
1013
description: The name of the database to use on SQLite Cloud, just remeber to create first a database on your project!
1114
required: true
@@ -56,7 +59,7 @@ runs:
5659
[[ ${{ inputs.strip-jsx }} == true ]] && args+=" --strip-jsx"
5760
[[ ${{ inputs.strip-md-titles }} == true ]] && args+=" --strip-md-titles"
5861
[[ ${{ inputs.strip-astro-header }} == true ]] && args+=" --strip-astro-header"
59-
echo $(main --input=${{ inputs.path }} --output=search.sql $args)
62+
echo $(main --input=${{ inputs.path }} --output=search.sql --base-url=${{ inputs.base-url }} $args)
6063
shell: bash
6164

6265
- name: Executes the .sql on SQLite Cloud

src/main.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ FILE *f = NULL;
4242

4343
const char *src_path = NULL;
4444
const char *dest_path = NULL;
45+
const char *base_url = NULL;
4546
bool strip_html = false;
4647
bool strip_jsx = false;
4748
bool strip_md_title = false;
@@ -95,7 +96,7 @@ static char *file_buildpath (const char *filename, const char *dirpath) {
9596
return full_path;
9697
}
9798

98-
static char *file_buildurl (const char *fullpath) {
99+
static char *file_buildurl (const char *base_url, const char *fullpath) {
99100
char *url = (char *)malloc(512);
100101
if (!url) return NULL;
101102

@@ -125,7 +126,6 @@ static char *file_buildurl (const char *fullpath) {
125126
}
126127
}
127128

128-
const char *base_url = "https://docs.sqlitecloud.io/docs/";
129129
snprintf(url, 512, "%s%s", base_url, p);
130130

131131
free(path);
@@ -469,7 +469,7 @@ static void add_entry(const char *url, char *buffer, size_t size) {
469469
#endif
470470
}
471471

472-
static void scan_docs (const char *dir_path) {
472+
static void scan_docs (const char *base_url, const char *dir_path) {
473473
DIRREF dir = opendir(dir_path);
474474
if (!dir) return;
475475

@@ -479,15 +479,15 @@ static void scan_docs (const char *dir_path) {
479479
// if file is a folder then start recursion
480480
const char *full_path = file_buildpath(target_file, dir_path);
481481
if (is_directory(full_path)) {
482-
scan_docs(full_path);
482+
scan_docs(base_url, full_path);
483483
continue;
484484
}
485485

486486
// test only files with a .md or mdx extension
487487
if ((strstr(full_path, ".md") == NULL) && (strstr(full_path, ".mdx") == NULL)) continue;
488488

489489
// build url and title
490-
const char *url = file_buildurl(full_path);
490+
const char *url = file_buildurl(base_url, full_path);
491491

492492
// load md source code
493493
size_t size = 0;
@@ -532,6 +532,14 @@ int main (int argc, char * argv[]) {
532532
.value_name = "output_path",
533533
.description = "Output path"
534534
},
535+
536+
{
537+
.identifier = 'b',
538+
.access_letters = "b",
539+
.access_name = "base-url",
540+
.value_name = "base_url",
541+
.description = "Base url in docs path"
542+
},
535543

536544
{
537545
.identifier = 'a',
@@ -614,6 +622,7 @@ int main (int argc, char * argv[]) {
614622
switch (cag_option_get_identifier(&context)) {
615623
case 'i': src_path = cag_option_get_value(&context); break;
616624
case 'o': dest_path = cag_option_get_value(&context); break;
625+
case 'b': base_url = cag_option_get_value(&context); break;
617626
case 'l': strip_html = true; break;
618627
case 'j': strip_jsx = true; break;
619628
case 'm': strip_md_title = true; break;
@@ -636,7 +645,7 @@ int main (int argc, char * argv[]) {
636645
}
637646

638647
create_output(dest_path);
639-
scan_docs(src_path);
648+
scan_docs(base_url, src_path);
640649
close_output();
641650

642651
return 0;

0 commit comments

Comments
 (0)