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

[question] Edit file button #162

Closed
Kikobeats opened this issue May 28, 2017 · 8 comments
Closed

[question] Edit file button #162

Kikobeats opened this issue May 28, 2017 · 8 comments

Comments

@Kikobeats
Copy link
Contributor

Hello!

I'm using docsify at JS MythBusters, thanks for the project, it looks amazing 😄.

One of my goals of the project is make easy people add more information.

Because every item of the table of contents is mapped with a markdown file, do you think that could be more or less easy add a "Edit file" button (like Wikipedia) and automatically create a PR associated with the project?

Maybe it could be written as a plugin.

@QingWei-Li
Copy link
Member

QingWei-Li commented May 28, 2017

Hi, @Kikobeats
We can get the file path through the built-in method, so it's easy to implement this plugin. For example

function(hook, vm) {
   const path = window.Docsify.route.parse().path
   console.log(vm.$getFile(path)) // such as `/README.md`
}

Do you want to submit a PR to implement it? 👻

@Kikobeats
Copy link
Contributor Author

could be good idea place the html for the button and put the href using js?

@QingWei-Li
Copy link
Member

@QingWei-Li
Copy link
Member

QingWei-Li commented May 30, 2017

Hi, @Kikobeats

I have added it to the doc, you can refer to this example.

window.$docsify = {
  plugins: [
    function(hook, vm) {
      hook.beforeEach(function (html) {
        var url = 'https://github.com/QingWei-Li/docsify/blob/master/docs' + vm.router.getFile()
        var editHtml = '[📝 EDIT DOCUMENT](' + url + ')\n'

        return editHtml
          + html
          + '\n----\n'
          + 'Last modified {docsify-updated} '
          + editHtml
      })
    }
  ]
}

@Kikobeats
Copy link
Contributor Author

amazing, let me try it into mythbusters website, thanks!

@Kikobeats
Copy link
Contributor Author

@QingWei-Li any idea how I can insert int after the first h1 ?

@QingWei-Li
Copy link
Member

Is it possible to use regular expression?

@Kikobeats
Copy link
Contributor Author

@QingWei-Li sounds very weird

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants