Search code examples
docpad

How to creat edit post button. Docpad


How to make the edit articles?

<a href="https://github.com/.../blob/master/src/documents/posts/<%=@document.name%>" target="_blank">edit</a>

But this does not work for file.html.md


Solution

  • You probably want to change @document.name to the appropriate path within the repository the file is located. We can use fullPath instead of name for this, but we'll need to replace the srcPath that DocPad is configured with in order to get just the path relative to your project, rather than the absolute path on the file system.

    <a href="https://github.com/.../blob/master/<%=@document.fullPath.replace(@srcPath,'')%>" target="_blank">edit</a>
    

    Now, @srcPath is not actually available to us, so we'll need to make it so. We can define srcPath in our template data by adding the following to our docpad configuration file:

    events:
        extendTemplateData: (opts) ->
            opts.templateData.srcPath = @docpad.getConfig().srcPath
    

    Let me know if it works. If not, please post more about what you were expecting, and what results you got, and I'll happily help further.