Skip to content

Commit

Permalink
website/scripts/docsmg: final version (#11501)
Browse files Browse the repository at this point in the history
* add docsmg tool

* moved to the correct scripts directory

* removed test files

* added install script and readme draft to docsmg

* fix install script

* fixed issues

* Revert "fixed issues"

This reverts commit a511920.

* Revert "Revert "fixed issues""

This reverts commit ab68918.

* added dotenv and updated readme

* fixed install script

* update readme to ensure that new installers of rust have envs loaded

* changed docsmg from using .env to docsmg.env

* fixed docsmg to fix internal links in file

* fixed docsmg migrate not making directories to file

* fixed docsmg migrate trying to read pngs to string

* did stuff

* fix links

* fix links 2

* fix links 3

* fix links

* fix links

* fix links

* fix links

* fix links

* fixed docsmg migrate replacing links

* fixed docsmg migrate replacing links

* fixed docsmg migrate replacing links

* fixed docsmg migrate replacing links

* fixed links

* update docsmg fixing links

* update docsmg fixing links

* update docsmg fixing links

* update docsmg removing empty directories

* remove changed docs

* Revert "remove changed docs"

This reverts commit 2e21a5b.

* remove changed docs

* fixed readme

---------

Signed-off-by: Tana M Berry <tanamarieberry@yahoo.com>
Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com>
  • Loading branch information
ObamaTheLlama114 and tanberry authored Sep 26, 2024
1 parent 4fbc13a commit ff53bcc
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 27 deletions.
39 changes: 39 additions & 0 deletions website/scripts/docsmg/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/scripts/docsmg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ anyhow = "1.0.86"
clap = { version = "4.5.9", features = ["derive", "env"] }
colored = "2.1.0"
dotenv = "0.15.0"
regex = "1.10.6"
tokio = "1.38.0"
6 changes: 6 additions & 0 deletions website/scripts/docsmg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Use this migration tool to:

## Steps to use

1. Generate a migratefile with `docsmg generate >> migratefile`
2. Find the files you want to move in `migratefile` and insert the path you want to move them to after the arrow; ex `path/to/move/from/file.md -> path/to/move/to/file.md` Note: make sure to put spaces on either side of the arrow or that line won't be recognized
3. Once you have entered all the paths you want to move, migrate the files with `docsmg migrate`
4. To revert the migration, use `docsmg unmigrate`; Note: DO NOT edit the migrate file in between steps 3 and 4
5. Repeat steps 2-4 until you are satisfied with the result

### Create the mapping file (`migratefile`)

1. Navigate to the `authentik/website` dir.
Expand Down
24 changes: 24 additions & 0 deletions website/scripts/docsmg/src/hackyfixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::{ffi::OsStr, fs::{read_to_string, write}, path::PathBuf};

use crate::recurse_directory;

pub fn add_extra_dot_dot_to_expression_mdx(migrate_path: PathBuf) {
let binding = recurse_directory(migrate_path);
let files = binding.iter().filter(|x| if let Some(i) = x.file_name() {
if Some("expression.mdx") == i.to_str() || Some("expressions.md") == i.to_str() {
true
} else {
false
}
} else {
false
});

for file in files {
let content = match read_to_string(file) {
Ok(i) => i,
_ => continue,
};
let _ = write(file, content.replace("../expressions", "../../expressions"));
}
}
34 changes: 34 additions & 0 deletions website/scripts/docsmg/src/links.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::{fs::read_to_string, path::PathBuf};

use regex::{Captures, Regex};

use crate::recurse_directory;

pub fn shorten_all_external_links(migrate_path: PathBuf) {
let files = recurse_directory(migrate_path.clone());
for file in files {
let file = migrate_path.join(file);
let absolute_file = file.clone().canonicalize().unwrap();
let contents = if let Ok(x) = read_to_string(file) {
x
} else {
continue;
};
let re = Regex::new(r"\[(?<name>.*)\]\((?<link>.*)\)").unwrap();
let captures: Vec<Captures> = re.captures_iter(&contents).collect();
for capture in captures {
let link = &capture["link"];
let link = PathBuf::from(link);
let absolute_link = absolute_file
.clone()
.parent()
.unwrap()
.join(link)
.canonicalize()
.unwrap();
shorten_link_relative_to(absolute_link.clone(), absolute_file.clone());
}
}
}

fn shorten_link_relative_to(link_to_shorten: PathBuf, relative_to: PathBuf) {}
2 changes: 2 additions & 0 deletions website/scripts/docsmg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use std::{fs, path::PathBuf};
use clap::{Parser, Subcommand};

mod generate;
mod links;
mod migrate;
mod migratefile;
mod r#move;
mod hackyfixes;

#[derive(Parser)]
struct Cli {
Expand Down
Loading

0 comments on commit ff53bcc

Please sign in to comment.