Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fankaiLiu committed Dec 20, 2023
1 parent 3700bb5 commit 4a48651
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
37 changes: 37 additions & 0 deletions locales/readme.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
_version: 2
dir:
en: Dir
zh_CN: 目录
zh_TW: 目錄
fr: Rép
ja: ディレクトリ
es: Dir
de: Verz
ru: Дир
it: Dir
pt: Dir
ko: 디렉토리
no: Mappe
is: Mappa
uk: Тека
th: ไดเรกทอรี
el: Φάκελος
da: Bibliotek
file:
en: File
zh_CN: 文件
zh_TW: 檔案
fr: Fichier
ja: ファイル
es: Archivo
de: Datei
ru: Файл
it: File
pt: Arquivo
ko: 파일
no: Fil
is: Skrá
uk: Файл
th: ไฟล์
el: Αρχείο
da: Fil
13 changes: 10 additions & 3 deletions src/utils/directory2md.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
use rust_i18n::t;
use std::fs::{self, File};
use std::io::{Result, Write};
use std::path::Path;
use walkdir::WalkDir;

pub fn write_directory_contents_to_markdown(output_file: &Path) -> Result<()> {
let mut file = File::create(output_file)?;
writeln!(file, "# Directory Contents\n")?;
let project_name = output_file
.parent()
.unwrap()
.file_name()
.unwrap_or_default()
.to_string_lossy();
writeln!(file, "# {}", project_name)?;
for entry in WalkDir::new(output_file.parent().unwrap())
.into_iter()
.filter_map(|e| e.ok())
Expand All @@ -21,10 +28,10 @@ pub fn write_directory_contents_to_markdown(output_file: &Path) -> Result<()> {
let file_name = file_name.to_string_lossy();
if metadata.is_dir() {
// Use `**Dir:**` to denote directories
writeln!(file, "{}- **Dir:** {}", indent, file_name)?;
writeln!(file, "{}- **{}:** {}", indent, t!("dir"), file_name)?;
} else {
// Use `*File:*` to denote files
writeln!(file, "{}- *File:* {}", indent, file_name)?;
writeln!(file, "{}- *{}:* {}", indent, t!("file"), file_name)?;
}
}
}
Expand Down

0 comments on commit 4a48651

Please sign in to comment.