Skip to content

Commit

Permalink
add github link to yml files.
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan committed Oct 30, 2023
1 parent 83c4083 commit 5860cd2
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions devtools/text-optimizer/src/yaml_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use super::{
GITHUB_REPO,
};
use serde::{Deserialize, Serialize};
use std::io::Read;
use std::io::Write;
use std::{fs::File, path::PathBuf};
use std::{io::Read, path::Path};

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Clone)]
pub struct TextInfoSave {
Expand All @@ -17,10 +17,13 @@ pub struct TextInfoSave {

impl TextInfoSave {
pub fn from_text_info(text_info: TextInfo, git_repo: &str, commit_id: &str) -> Self {
// 使用 Metadata 的 from_meta 方法进行 Meta 到 Metadata 的转换
let metadata = Metadata::from_meta(text_info.metadata(), git_repo, commit_id);
let metadata = Metadata::from_meta(
text_info.metadata(),
git_repo,
commit_id,
text_info.metadata().file(),
);

// 创建 TextInfoSave 结构体并返回
TextInfoSave {
original: text_info.original().to_owned(),
editable: text_info.editable().to_owned(),
Expand All @@ -37,12 +40,9 @@ pub struct Metadata {
}

impl Metadata {
// 定义从 Meta 到 Metadata 的转换方法
pub fn from_meta(meta: &Meta, github_repo: &str, commit_id: &str) -> Self {
// 创建 GitHub 代码行链接的前缀
let github_link_prefix = format!("{}/{}/", github_repo, commit_id);

// 为每个代码行生成 GitHub 链接
pub fn from_meta(meta: &Meta, github_repo: &str, commit_id: &str, file: &Path) -> Self {
let file = file.strip_prefix("../..").expect("strip prefix");
let github_link_prefix = format!("{}/{}/{}", github_repo, commit_id, file.display());
let code_line_link: Vec<String> = meta
.start_lines()
.iter()
Expand Down

0 comments on commit 5860cd2

Please sign in to comment.