File tree 3 files changed +35
-3
lines changed
docs/content/doc/developers
3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -24,3 +24,22 @@ If you are looking for [CI/CD](https://gitea.com/gitea/awesome-gitea#user-conten
24
24
an [ SDK] ( https://gitea.com/gitea/awesome-gitea#user-content-sdk ) ,
25
25
or even some extra [ themes] ( https://gitea.com/gitea/awesome-gitea#user-content-themes ) ,
26
26
you can find them listed in the [ awesome-gitea] ( https://gitea.com/gitea/awesome-gitea ) repository!
27
+
28
+ ## Pre-Fill New File name and contents
29
+
30
+ If you'd like to open a new file with a given name and contents,
31
+ you can do so with query parameters:
32
+
33
+ ``` txt
34
+ GET /{{org}}/{{repo}}/_new/{{filepath}}
35
+ ?filename={{filename}}
36
+ &value={{content}}
37
+ ```
38
+
39
+ For example:
40
+
41
+ ``` txt
42
+ GET https://git.example.com/johndoe/bliss/_new/articles/
43
+ ?filename=hello-world.md
44
+ &value=Hello%2C%20World!
45
+ ```
Original file line number Diff line number Diff line change @@ -81,7 +81,11 @@ func editFile(ctx *context.Context, isNewFile bool) {
81
81
return
82
82
}
83
83
84
- treeNames , treePaths := getParentTreeFields (ctx .Repo .TreePath )
84
+ // Check if the filename (and additional path) is specified in the querystring
85
+ // (filename is a misnomer, but kept for compatibility with Github)
86
+ filePath , fileName := path .Split (ctx .Req .URL .Query ().Get ("filename" ))
87
+ filePath = strings .Trim (filePath , "/" )
88
+ treeNames , treePaths := getParentTreeFields (path .Join (ctx .Repo .TreePath , filePath ))
85
89
86
90
if ! isNewFile {
87
91
entry , err := ctx .Repo .Commit .GetTreeEntryByPath (ctx .Repo .TreePath )
@@ -136,7 +140,8 @@ func editFile(ctx *context.Context, isNewFile bool) {
136
140
ctx .Data ["FileContent" ] = content
137
141
}
138
142
} else {
139
- treeNames = append (treeNames , "" ) // Append empty string to allow user name the new file.
143
+ // Append filename from query, or empty string to allow user name the new file.
144
+ treeNames = append (treeNames , fileName )
140
145
}
141
146
142
147
ctx .Data ["TreeNames" ] = treeNames
Original file line number Diff line number Diff line change @@ -1825,7 +1825,7 @@ async function initEditor() {
1825
1825
const $editArea = $ ( '.repository.editor textarea#edit_area' ) ;
1826
1826
if ( ! $editArea . length ) return ;
1827
1827
1828
- await createCodeEditor ( $editArea [ 0 ] , $editFilename [ 0 ] , previewFileModes ) ;
1828
+ const editor = await createCodeEditor ( $editArea [ 0 ] , $editFilename [ 0 ] , previewFileModes ) ;
1829
1829
1830
1830
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
1831
1831
// to enable or disable the commit button
@@ -1849,6 +1849,14 @@ async function initEditor() {
1849
1849
}
1850
1850
} ) ;
1851
1851
1852
+ // Update the editor from query params, if available,
1853
+ // only after the dirtyFileClass initialization
1854
+ const params = new URLSearchParams ( window . location . search ) ;
1855
+ const value = params . get ( 'value' ) ;
1856
+ if ( value ) {
1857
+ editor . setValue ( value ) ;
1858
+ }
1859
+
1852
1860
$commitButton . on ( 'click' , ( event ) => {
1853
1861
// A modal which asks if an empty file should be committed
1854
1862
if ( $editArea . val ( ) . length === 0 ) {
You can’t perform that action at this time.
0 commit comments