Skip to content

[new feature] add post edit button#208

Merged
ivan-nginx merged 4 commits intotheme-next:masterfrom
xu-song:master
Apr 11, 2018
Merged

[new feature] add post edit button#208
ivan-nginx merged 4 commits intotheme-next:masterfrom
xu-song:master

Conversation

@xu-song
Copy link
Contributor

@xu-song xu-song commented Apr 3, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines.
  • Tests for the changes have been added (for bug fixes / features).
    • Muse | Mist have been tested.
    • Pisces | Gemini have been tested.
  • Docs have been added / updated (for bug fixes / features).

PR Type

What kind of change does this PR introduce?

  • Bugfix.
  • Feature.
  • Code style update (formatting, local variables).
  • Refactoring (no functional changes, no api changes).
  • Build related changes.
  • CI related changes.
  • Documentation content changes.
  • Other... Please describe:

What is the new behavior?

Add edit button for each post.

It provides a way of online edit. In addition, links to github is a good way forcollaborative edit.

How it looks?

common style

hover style

Live demo here.

How to use?

In NexT _config.yml:

# Post edit
post_edit:
  enable: true
  url: https://github.com/ESblog/_posts/tree/master/   # view source
# url: https://github.com/ESblog/_posts/edit/master/   # fork and edit

The above demo page, links to
https://github.com/ESblog/_posts/tree/master/web/blog-framework/nodejs-hexo/plugin/hexo-plugin-recommendation.md according to the file path_post/web/blog-framework/nodejs-hexo/plugin/hexo-plugin-recommendation.md.

Does this PR introduce a breaking change?

  • Yes.
  • No.

@ES-tool ES-tool mentioned this pull request Apr 3, 2018
@xu-song xu-song mentioned this pull request Apr 3, 2018
17 tasks
#}{% else %}
{{ post.title }}
{% if theme.post_edit.enable %}
<a href="{{theme.post_edit.url}}{{post.source.slice(7)}}" class="article-edit-link" title="{{ __('post.edit') }}"><i class="fa fa-pencil"></i></a>
Copy link
Member

@ivan-nginx ivan-nginx Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can i ask what's mean post.source.slice(7)? I'm interesting in slice(7) parameter. Especially in number 7.

Copy link
Contributor Author

@xu-song xu-song Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post.source starts with _post/

in the above case

post.source = `_post/web/blog-framework/nodejs-hexo/plugin/hexo-plugin-recommendation.md`

Generally, we need to get the post path, which not include _post/ .

post.source.slice(7) = 'web/blog-framework/nodejs-hexo/plugin/hexo-plugin-recommendation.md'
post_edit.url = 'https://github.com/ESblog/_posts/tree/master/'
post_edit.url+post.source.slice(7) = 'https://github.com/ESblog/_posts/tree/master/web/blog-framework/nodejs-hexo/plugin/hexo-plugin-recommendation.md'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether all the post.source starts with _post/. Maybe need to be optimized.

@xu-song
Copy link
Contributor Author

xu-song commented Apr 4, 2018

URL setting

url setting depends on the resource project in github.

1. For site repository

e.g. https://github.com/hexojs/hexo-starter

we can set

url:https://github.com/hexojs/hexo-starter/tree/master/source/_posts/   # view
# url:https://github.com/hexojs/hexo-starter/edit/master/source/_posts/   # edit

2. For post repository

e.g. https://github.com/ESblog/_posts

we can set

url:https://github.com/ESblog/_posts/tree/master/    # view
# url:https://github.com/ESblog/_posts/edit/master/    # edit 

Implementation

We need a way that works for both the above cases. Thus post.source.slice(7) is used.

Maybe a better way, a more general way can be used.

@ivan-nginx
Copy link
Member

Ooh, i see. It's cutted out main Github link of repository, right?

@xu-song
Copy link
Contributor Author

xu-song commented Apr 4, 2018

Yes. Any suggestion and optimization is welcome.

@sli1989
Copy link
Collaborator

sli1989 commented Apr 4, 2018

Need upload resource md?

@xu-song
Copy link
Contributor Author

xu-song commented Apr 4, 2018

Yes.
You should create a resource repository. As mentioned above, there are two common ways,
You can either upload your full site repository, or post only.

I prefer the second way, which sets the _post as a standalone project, a submodule of site repository.

@ivan-nginx ivan-nginx added this to the v6.2.0 milestone Apr 11, 2018
@ivan-nginx ivan-nginx merged commit fae8127 into theme-next:master Apr 11, 2018
ivan-nginx referenced this pull request Apr 11, 2018
1. Disable post edit option by default.
2. Aligment post header to center with edit button enabled.
3. Add conditional import in post edit styles.
tongluyang pushed a commit to tongluyang/hexo-theme-next that referenced this pull request Nov 19, 2019
* new feature: post edit

* Updated feature for post edit.

* Remove excess blank lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants