Skip to content

Commit 9057619

Browse files
committed
added "status: draft" support in the strip astro header option that's now renamed to use front matter; fixed missing "-" character from the options column
1 parent 171da0f commit 9057619

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
project-string: ${{ secrets.PROJECT_STRING }}
1818
base-url: https://your-website.com/docs/
1919
database: documentation.sqlite
20-
strip-astro-header: true
20+
use-front-matter: true
2121
strip-md-titles: true
2222
strip-jsx: true
2323
strip-html: true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
uses: actions/checkout@v4
4040

4141
- name: Build SQLite Cloud database
42-
uses: sqlitecloud/docsearch-action@v3
42+
uses: sqlitecloud/docsearch-action@v4
4343
with:
4444
project-string: ${{ secrets.PROJECT_STRING }}
4545
base-url: https://your-website.com/docs/
@@ -56,7 +56,7 @@ jobs:
5656
* Set the `strip-html` input to `true` if you want to remove HTML elements.
5757
* Set the `strip-jsx` input to `true` if you want to remove JSX elements.
5858
* 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 and put it in the `documentation` table as a JSON Object.
59+
* Set the `use-front-matter` input to `true` if you want to move the front matter to the `documentation` table as a JSON Object.
6060
* Set the `path-using-slug` input to `true` if you want to use the slug in the header as the path instead of the relative one for the URL.
6161
7. Commit and push the workflow file to your repository.
6262

action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ inputs:
2828
description: If you want to avoid redundancy of your markdown titles in the search set this to true.
2929
required: false
3030
default: false
31-
strip-astro-header:
32-
description: If you use Astro and you want to remove its docs header make this true.
31+
use-front-matter:
32+
description: If you use a front matter and you want the action to convert it to json and send it to the cloud make this true.
3333
required: false
3434
default: false
3535
path-using-slug:
@@ -62,7 +62,7 @@ runs:
6262
[[ ${{ inputs.strip-html }} == true ]] && args+=" --strip-html"
6363
[[ ${{ inputs.strip-jsx }} == true ]] && args+=" --strip-jsx"
6464
[[ ${{ inputs.strip-md-titles }} == true ]] && args+=" --strip-md-titles"
65-
[[ ${{ inputs.strip-astro-header }} == true ]] && args+=" --strip-astro-header"
65+
[[ ${{ inputs.use-front-matter }} == true ]] && args+=" --use-front-matter"
6666
[[ ${{ inputs.path-using-slug }} == true ]] && args+=" --path-using-slug"
6767
echo $(main --input=${{ inputs.path }} --output=search.sql --base-url=${{ inputs.base-url }} $args)
6868
shell: bash

src/main.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
#define GENERATE_SQLITE_DATABASE 0
10-
#define DOCBUILDER_VERSION "0.3"
10+
#define DOCBUILDER_VERSION "0.4"
1111

1212
#include <stdio.h>
1313
#include <fcntl.h>
@@ -26,6 +26,8 @@
2626
#define PATH_SEPARATOR '/'
2727

2828
#define NEXT input[i++]
29+
#define PREV2 input[i-3]
30+
#define PREV input[i-2]
2931
#define CURRENT input[i-1]
3032
#define PEEK input[i]
3133
#define PEEK2 input[i+1]
@@ -35,7 +37,7 @@
3537
#define SKIP_UNTIL(_c) do{i++;} while(PEEK == _c)
3638
#define RESET_SKIP() do {toskip = NO_SKIP; nskip = 1;} while(0)
3739

38-
#define OPTIONS_COL json_mode && strip_astro_header
40+
#define OPTIONS_COL json_mode && use_front_matter
3941

4042
#if GENERATE_SQLITE_DATABASE
4143
sqlite3 *db = NULL;
@@ -48,12 +50,13 @@ const char *base_url = NULL;
4850
bool strip_html = false;
4951
bool strip_jsx = false;
5052
bool strip_md_title = false;
51-
bool strip_astro_header = false;
53+
bool use_front_matter = false;
5254
bool use_transaction = false;
5355
bool json_mode = false;
5456
bool path_using_slug = false;
5557
bool use_database = false;
5658
bool create_db = false;
59+
bool status_draft = false;
5760

5861
// MARK: - I/O Utils -
5962

@@ -77,6 +80,7 @@ static char *directory_read (DIRREF ref) {
7780
}
7881
if (d->d_name[0] == '\0') continue;
7982
if (d->d_name[0] == '.') continue;
83+
//if (use_front_matter && d->d_name[0] == '_') continue; // skipping files starting with _ like astro does
8084
return (char *)d->d_name;
8185
}
8286
return NULL;
@@ -226,14 +230,20 @@ static char *process_md (const char *input, char *buffer, size_t *len, char *ast
226230
if (c == toskip) {
227231
if (nskip == 1) {
228232
RESET_SKIP();
229-
} else if ((nskip == 3) && (PEEK == toskip) && (PEEK2 == toskip)) {
230-
NEXT; // -
231-
NEXT; // -
232-
NEXT; // \n
233-
RESET_SKIP();
233+
} else if (nskip == 3) {
234+
if((PEEK == toskip) && (PEEK2 == toskip)){
235+
NEXT; // -
236+
NEXT; // -
237+
NEXT; // \n
238+
RESET_SKIP();
239+
} else if( ((PREV != toskip) && (PEEK != toskip)) || ((PREV != toskip) && (PREV2 != toskip)) ) astro_header[h++] = c;
234240
}
235241
} else if(toskip == '-' && nskip == 3) {
236242
if(path_using_slug && c == '\n' && PEEK == 's' && PEEK2 == 'l' && check_line(&input[i-1], "\nslug: ", "\n")) slug_index += i;
243+
if(use_front_matter && c == '\n' && PEEK == 's' && PEEK2 == 't' && check_line(&input[i-1], "\nstatus:", "draft")){
244+
status_draft = true;
245+
return NULL;
246+
}
237247
astro_header[h++] = c;
238248
}
239249
continue;
@@ -338,7 +348,7 @@ static char *process_md (const char *input, char *buffer, size_t *len, char *ast
338348
}
339349

340350
case '-': {
341-
if ((PEEK == '-') && (PEEK2 == '-') && strip_astro_header) {
351+
if ((PEEK == '-') && (PEEK2 == '-') && use_front_matter) {
342352
if (i == 1) {
343353
// process meta
344354
SET_SKIP_N('-', 3);
@@ -619,6 +629,8 @@ static void scan_docs (const char *base_url, const char *dir_path) {
619629

620630
const char *slug_path = process_md(source_code, buffer, &size, astro_header, &header_size);
621631

632+
if(status_draft) continue;
633+
622634
if(OPTIONS_COL) process_json(astro_header, &header_size);
623635

624636
// build url and title
@@ -682,7 +694,7 @@ int main (int argc, char * argv[]) {
682694
{
683695
.identifier = 'a',
684696
.access_letters = "a",
685-
.access_name = "strip-astro-header",
697+
.access_name = "use-front-matter",
686698
.value_name = NULL,
687699
.description = "Remove Astro header"
688700
},
@@ -772,7 +784,7 @@ int main (int argc, char * argv[]) {
772784
case 'l': strip_html = true; break;
773785
case 'j': strip_jsx = true; break;
774786
case 'm': strip_md_title = true; break;
775-
case 'a': strip_astro_header = true; break;
787+
case 'a': use_front_matter = true; break;
776788
case 't': use_transaction = true; break;
777789
case 'u': use_database = true; break;
778790
case 's': json_mode = true; break;

0 commit comments

Comments
 (0)