@@ -4,9 +4,9 @@ use super::{
4
4
GITHUB_REPO ,
5
5
} ;
6
6
use serde:: { Deserialize , Serialize } ;
7
- use std:: io:: Read ;
8
7
use std:: io:: Write ;
9
8
use std:: { fs:: File , path:: PathBuf } ;
9
+ use std:: { io:: Read , path:: Path } ;
10
10
11
11
#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Hash , Clone ) ]
12
12
pub struct TextInfoSave {
@@ -17,10 +17,13 @@ pub struct TextInfoSave {
17
17
18
18
impl TextInfoSave {
19
19
pub fn from_text_info ( text_info : TextInfo , git_repo : & str , commit_id : & str ) -> Self {
20
- // 使用 Metadata 的 from_meta 方法进行 Meta 到 Metadata 的转换
21
- let metadata = Metadata :: from_meta ( text_info. metadata ( ) , git_repo, commit_id) ;
20
+ let metadata = Metadata :: from_meta (
21
+ text_info. metadata ( ) ,
22
+ git_repo,
23
+ commit_id,
24
+ text_info. metadata ( ) . file ( ) ,
25
+ ) ;
22
26
23
- // 创建 TextInfoSave 结构体并返回
24
27
TextInfoSave {
25
28
original : text_info. original ( ) . to_owned ( ) ,
26
29
editable : text_info. editable ( ) . to_owned ( ) ,
@@ -37,12 +40,9 @@ pub struct Metadata {
37
40
}
38
41
39
42
impl Metadata {
40
- // 定义从 Meta 到 Metadata 的转换方法
41
- pub fn from_meta ( meta : & Meta , github_repo : & str , commit_id : & str ) -> Self {
42
- // 创建 GitHub 代码行链接的前缀
43
- let github_link_prefix = format ! ( "{}/{}/" , github_repo, commit_id) ;
44
-
45
- // 为每个代码行生成 GitHub 链接
43
+ pub fn from_meta ( meta : & Meta , github_repo : & str , commit_id : & str , file : & Path ) -> Self {
44
+ let file = file. strip_prefix ( "../.." ) . expect ( "strip prefix" ) ;
45
+ let github_link_prefix = format ! ( "{}/{}/{}" , github_repo, commit_id, file. display( ) ) ;
46
46
let code_line_link: Vec < String > = meta
47
47
. start_lines ( )
48
48
. iter ( )
0 commit comments