The Wayback Machine - https://web.archive.org/web/20220212203852/https://github.com/go-gitea/gitea/pull/16556
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-fill suggested New File 'name' and 'content' with Query Params #16556

Merged
merged 4 commits into from Jul 29, 2021

Conversation

@coolaj86
Copy link
Contributor

@coolaj86 coolaj86 commented Jul 27, 2021

Re: #16398

Use the same GET as the "New File" link, as seen here:

Screen Shot 2021-07-27 at 7 00 32 PM

And allow 3rd-party frontends to append ?filename=x&value=y to pre-populate the form:

Screen Shot 2021-07-27 at 7 01 19 PM

See also: Screen Capture Demo.

Pre-Fill New File Name & Contents w/ Query Params

If you'd like to open the New File page with suggested name and contents,
you can do so with the filename and value query parameters (just like GitHub):

GET /{{org}}/{{repo}}/_new/{{filepath}}
    ?filename={{filename}}
    &value={{content}}

For example:

GET https://git.example.com/johndoe/bliss/_new/articles/
    ?filename=hello-world.md
    &value=Hello%2C%20World!

This mirrors the documented behavior of Github, and fixes the known bug. Gist will also have this feature soon.

For Integration with File Templates

This allows you to use File Templating tools such as Bliss - which allows you to create blog articles, with FrontMatter, for Static Site blogs - acting as a de facto frontend for such platforms.

Test Binary

# Install Go
curl -sS https://webinstall.dev/golang | bash
# Clone Repo and Build
git clone https://github.com/coolaj86/gitea

pushd ./gitea

git checkout bliss

TAGS="bindata sqlite sqlite_unlock_notify" make build
@lunny
Copy link
Member

@lunny lunny commented Jul 27, 2021

Re: #16398

Pre-Fill New File Name & Contents w/ Query Params

If you'd like to create a new file with a given name and contents,
you can do so with query parameters:

GET /{{org}}/{{repo}}/_new/{{filepath}}
    ?filename={{filename}}
    &value={{content}}

For example:

GET https://git.example.com/johndoe/bliss/_new/articles/
    ?filename=hello-world.md
    &value=Hello%2C%20World!

To create or update a file, GET is not a suitable method.

@techknowlogick
Copy link
Member

@techknowlogick techknowlogick commented Jul 27, 2021

To create or update a file, GET is not a suitable method.

@lunny this won't create the file, it will only pre-fill the textarea to suggest content. The user will need to hit "Submit" to do a POST and then the file will be created.

modules/context/context.go Outdated Show resolved Hide resolved
@coolaj86 coolaj86 changed the title Add query params for pre-defined filename and content Pre-fill suggested New File 'name' and 'content' with Query Params Jul 27, 2021
routers/web/repo/editor.go Outdated Show resolved Hide resolved
routers/web/repo/editor.go Show resolved Hide resolved
lunny
lunny approved these changes Jul 28, 2021
@6543
Copy link
Member

@6543 6543 commented Jul 28, 2021

I still think we should have a ctx.Query who do action on query of url directly but this is not the scope of this pull

6543
6543 approved these changes Jul 28, 2021
@codecov-commenter

This comment has been hidden.

modules/context/context.go Outdated Show resolved Hide resolved
@6543
Copy link
Member

@6543 6543 commented Jul 28, 2021

@coolaj86 did revert your comment since we should do this in #16562 :)

Copy link
Member

@6543 6543 left a comment

sorry to hold you back but ...

@6543
Copy link
Member

@6543 6543 commented Jul 28, 2021

... it works all right beside you have to edit the filename box in UI to enable the Commit Changes button :/

beside that it's good to go

@coolaj86
Copy link
Contributor Author

@coolaj86 coolaj86 commented Jul 28, 2021

@6543 It looks like you already pushed a commit to revert it?

I see "1 change requested", but I don't see what change is request.

@coolaj86 coolaj86 force-pushed the bliss branch 2 times, most recently from 6ed3869 to 841a68b Jul 28, 2021
6543
6543 approved these changes Jul 29, 2021
@6543 6543 merged commit b9a0e33 into go-gitea:main Jul 29, 2021
2 checks passed
@6543
Copy link
Member

@6543 6543 commented Jul 29, 2021

@coolaj86 happy blogging :)

AbdulrhmnGhanem added a commit to kitspace/gitea that referenced this issue Aug 10, 2021
…o-gitea#16556)

* feature: add (GitHub-style) querystrings for pre-filling new file content

* docs: add query parameters for new files
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants