@@ -62,6 +62,29 @@ const CATEGORY_EMOJIS = {
6262/** @type {string[] } */
6363const CATEGORY_ORDER = [ 'guide' , 'tutorial' , 'reference' , 'best-practices' , 'cli' , 'tools' , 'ecosystem' , 'app' , 'other' ] ;
6464
65+ /**
66+ * Generate preview path from file path
67+ * @param {string } filepath - File path relative to adev-ja
68+ * @returns {string } Preview path for angular.jp
69+ */
70+ function generatePreviewPath ( filepath ) {
71+ const basePath = filepath
72+ . replace ( 'src/content/' , '' )
73+ . replace ( / \/ R E A D M E \. m d $ / , '' ) // READMEの場合はディレクトリのみ
74+ . replace ( / \. m d $ / , '' ) ;
75+
76+ // チュートリアルの特殊なパス変換
77+ if ( basePath . startsWith ( 'tutorials/' ) ) {
78+ // tutorials/first-app/intro -> tutorials/first-app
79+ // tutorials/first-app/steps/01-hello-world -> tutorials/first-app/01-hello-world
80+ return basePath
81+ . replace ( / \/ i n t r o $ / , '' ) // intro ディレクトリを削除
82+ . replace ( / \/ s t e p s \/ / , '/' ) ; // steps/ を削除
83+ }
84+
85+ return basePath ;
86+ }
87+
6588/**
6689 * Generate URLs for a file
6790 * @param {string } filepath - File path relative to adev-ja
@@ -78,14 +101,9 @@ function generateLinks(filepath) {
78101 const issueUrl = `https://github.com/angular/angular-ja/issues/new?template=translation-checkout.md&title=${ encodeURIComponent ( 'translate: ' + title ) } ` ;
79102
80103 // .mdファイルのみプレビューURL生成
81- let previewUrl = null ;
82- if ( filepath . endsWith ( '.md' ) ) {
83- const previewPath = filepath
84- . replace ( 'src/content/' , '' )
85- . replace ( / \/ R E A D M E \. m d $ / , '' ) // READMEの場合はディレクトリのみ
86- . replace ( / \. m d $ / , '' ) ;
87- previewUrl = `https://angular.jp/${ previewPath } ` ;
88- }
104+ const previewUrl = filepath . endsWith ( '.md' )
105+ ? `https://angular.jp/${ generatePreviewPath ( filepath ) } `
106+ : null ;
89107
90108 return { githubUrl, previewUrl, issueUrl } ;
91109}
0 commit comments