Giter Club home page Giter Club logo

nanopub's Introduction

MicroPub support for Static Blog Engine

Following long deliberation, all development will take place at https://ringdown.ascraeus.org/dgold/nanopub

Note This release removes support for syndicating to twitter.com.

This php script provides micropub support for Static Site Generators. Incoming posts are rewritten to a suitable front-matter format and saved to the user's content store.

Currently, the script will handle the following indieweb functions:-

  • notes
  • articles
  • replies, adding the title of the article/note you are replying to. Replies can be syndicated to external services.
  • photos, note that this functionality requires the use of JSON-posts. nanopub is not presently equipped to handle multipart uploads
  • checkins, this functionality is heavily informed by OwnYourSwarm and the format that service uses
  • bookmarks
  • like-of
  • repost

nanopub offers the following functionality as described in the formal Micropub Specification

Required

  • Supports header and form parameter methods of authentication
  • Supports creating posts using x-www-form-urlencoded syntax

Optional

  • Supports updating and deleting posts
  • Supports JSON syntax and source content query
  • Supports replacement and deletion of limited set of properties
  • As it uses a separate Media Endpoint it provides configuration query

Full implementation report is available on micropub.rocks

nanopub additionally supports syndication of content to external silos. Currently it provides syndication to Mastodon, although it also provides a framework implementation for any modern API-based endpoint. An example is provided of the script pinging the micro.blog service to update the user's feed.

The code is self-explanatory and documented, and can be adjusted easily to meet different needs.

Installation

Please refer to the Installation Notes

Client Notes

nanopub expects data inputs in accordance with the current (May 2017) Micropub Spec, and does not gracefully handled deprecated formats. In particular:

  • mp-slug, not slug when setting the content of the slug property
  • mp-syndicate-to not syndicate-to when setting syndication targets for POSSE

Any errors resulting from use of the deprecated formats are a matter for the client.

TODO

  • Make a setup.php script to complete the required configuration settings.
  • Implement rsvp's, itineraries &c

Author

Licences

Acknowledgments

  • The IndieAuth validation sequence was taken from Amy Guy's Minimal Micropub, without which I couldn't have done this.
  • All at the #indieweb and #indieweb-dev IRC channels, who provide inspiration and support in equal measure.
  • @lyda

Changes

Version Date Notes
2.0.1 2019-01-04 Changed licence to BSD 3-Clause Clear
2.0.0 2018-08-09 Removed support for syndication to twitter
1.5.1 2018-04-12 Clarified Installation & packaged vendor files
1.5 2018-02-01 Added configurable frontmatter, currently json or yaml
1.4 2018-01-26 Extended for weather reporting, and rich-context likes/reposts
1.2 2018-01-02 Expansion to include repost & like posts.
1.1 2017-11-14 Rewrite of script to remove redundant and repetitive code.
FIX: Added a getallheaders() replacement for web servers without apache functions
1.0 2017-10-17 First official release.

If someone is able to show me that what I think or do is not right, I will happily change, for I seek the truth, by which no one ever was truly harmed.
– Marcus Aurelius, Meditations, VI.21

nanopub's People

Contributors

dg01d avatar zegnat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nanopub's Issues

Feature request: Allow querying weather service to be optional feature

Hello,

Thank-you so much for addressing #3. I’m stumbling across a few things as I try to install this on my own server, so thought I would file issues as I come across them. Hope you don’t mind?

Okay, so the first issue is that setting up Compass is non-trivial, and I’m not sure necessary for basic functionality (although I am curious, so might set this up in the future). Ideally, this would be an optional feature, that would only be activated should the required configuration/keys be available.

For the moment, I have just commented out the following lines, which seems to do the trick:

// $weather = getWeather();
// $frontmatter = array_merge($frontmatter, $weather);

Understanding the nanopub flow

Hello,

I came across this post by you.

So, after nanopub does its thing.. you do have to rerun hugo. So that makes sense.

But then, the questions are:

  • What triggers nanopub to generate new content?
  • How does nanopub find the Hugo site source? i.e the content/ dir to save that new content to.. because the script is running on my domain.. which has no access to the actually site source in Markdown.
  • Does nanopub itself trigger hugo rerun?
    • How do you trigger hugo rerun via nanopub for your site?
  • I use Netlify, so the hugo rerun can be triggered using curl -X POST -d '' https://api.netlify.com/build_hooks/MY_API".
    • Can nanopub make that curl call?
    • Can I configure that MY_API as an env var, that nanopub can pick up? I wouldn't want to commit that to configs.php publicly (if you add that option).
  • How do you save that newly generated content by nanopub?
    • Do you need to save that? Or does nanopub generate the whole fresh content from scratch each time?
    • If you do save, how to you do it? Do you or can you git commit that to a separate repo?

So many questions!

All of this can theoretically work if nanopub is able to create new content on Netlify disk.. which I don't know how to test.

Generated file is always named Array.md

Not sure if I’ve not got something set up correctly – or perhaps because I’m not using Hugo (I’m testing using a bare site that only includes the code for nanopub) – but when posting via Quill, the resulting file is always called Array.md.

Add support for YAML front matter format

Hello! This looks like a fantastic project – although sadly just one of only a few options available for anyone wanting to implement MicroPub and publish to a statically-generated site.

How difficult/possible would it be to add support for documents that use YAML for their front matter data, rather than JSON? I know Hugo documents can use YAML as well as JSON (and TOML), but perhaps more to the point, Jekyll documents only use YAML. Adding this format would increase the number of static generators Nanopub is able to support. (Looking at the code, I suspect being able to configure where documents are saved would be needed to fully support Jekyll, but I can add that as a separate issue, if that’s the case.)

Any plans to support YAML? If not, pointers as to where and what to edit would be most helpful.

Thanks,

Paul

Feature request: Publish to GitHub

This feature request is probably quite a complex and far reaching, but adding for consideration. This feature can be seen in other similar Micropub libraries (webpage-micropub-to-github, micropub-github-pages), where the resulting document is saved to a GitHub repo, rather than directly to a server.

This is particularly useful for those cases where a site is hosted with GitHub Pages, if a publisher wishes to version their files, or generate them as part of a continuous integration workflow.

Installation clarification

Hello,

In the Installation instructions, it says:

Since the 1.2 release, nanopub requires the use of Composer. Getting it to do all the things I wanted it to do was getting way beyond my skill level.

I have 0 experience with PHP, and don't plan to tinker with the code.

So I assume that installing Composer is not a requirement?

Can you please list the installation steps just to get the endpoint running for someone with no PHP experience like myself?

Possible to set the config.php values from env var?

Hello,

The config.php needs twitter api and stuff, which I believe shouldn't be publicly committed? or not committed to git at all, even if private?

Can those be set using env vars?

(On Netlify, I can set env vars like TWITTER_API_SECRET, and php can then read the value from the env var?)

[my config.php so far -- I am just committing things to my static dir for now, and then see how it goes.. I still have a big questionmark if this will even work for me on Netlify where I don't own/manage the hosting space.]

Plugin mechanism

I have a need for my micropub endpoint to occasionally do something more than just create a YAML file. I might want to add elements to a JSON data structure for use with Hugo data-driven templates, for example. It would be swell if Nanopub could support invoking additional scripts by way of a plugin mechanism.

Undefined indices

Trying to get nanopub working on a site running PHP7, and getting errors.

php composer.phar install worked:

# php composer.phar install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Package operations: 19 installs, 0 updates, 0 removals
  - Installing guhelski/forecast-php (1.1.1): Downloading (100%)
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
  - Installing guzzlehttp/guzzle (6.3.0): Downloading (100%)
  - Installing j7mbo/twitter-api-php (1.0.6): Downloading (100%)
  - Installing p3k/timezone (0.1.0): Downloading (100%)
  - Installing mf2/mf2 (v0.3.2): Downloading (100%)
  - Installing indieweb/link-rel-parser (0.1.3): Downloading (100%)
  - Installing p3k/http (0.1.5): Downloading (100%)
  - Installing zendframework/zendxml (1.0.2): Downloading (100%)
  - Installing miniflux/picofeed (v0.1.37): Downloading (100%)
  - Installing facebook/graph-sdk (5.6.1): Downloading (100%)
  - Installing ezyang/htmlpurifier (v4.9.3): Downloading (100%)
  - Installing dg/twitter-php (v3.6): Downloading (100%)
  - Installing cebe/markdown (1.1.2): Downloading (100%)
  - Installing p3k/xray (v1.4.2): Downloading (100%)
  - Installing symfony/yaml (v3.4.4): Downloading (100%)
  - Installing tantek/cassis (v0.2.16895): Downloading (100%)
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
mf2/mf2 suggests installing barnabywalters/mf-cleaner (To more easily handle the canonical data php-mf2 gives you)
facebook/graph-sdk suggests installing paragonie/random_compat (Provides a better CSPRNG option in PHP 5)
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
Generating autoload files

I ran the update, as suggested:

# php composer.phar update
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 7 updates, 1 removal
  - Removing miniflux/picofeed (v0.1.37)
  - Updating facebook/graph-sdk (5.6.1 => 5.6.2): Downloading (100%)
  - Installing p3k/picofeed (v0.1.38): Downloading (100%)
  - Updating mf2/mf2 (v0.3.2 => v0.4.3): Downloading (100%)
  - Updating p3k/http (0.1.5 => 0.1.7): Downloading (100%)
  - Updating ezyang/htmlpurifier (v4.9.3 => v4.10.0): Downloading (100%)          - Updating p3k/xray (v1.4.2 => v1.4.23): Downloading (100%)
  - Updating guzzlehttp/guzzle (6.3.0 => 6.3.2): Downloading (100%)
  - Updating symfony/yaml (v3.4.4 => v3.4.8): Downloading (100%)
Writing lock file
Generating autoload files

Here are the errors:

[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Notice:  Undefined index: like_site in /var/www/html/known/micropub/nanopub.php on line 559"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Notice:  Undefined index: repost_site in /var/www/html/known/micropub/nanopub.php on line 573"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Notice:  Undefined index: replysite in /var/www/html/known/micropub/nanopub.php on line 587"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function Symfony\Component\Yaml\ctype_digit() in /var/www/html/known/micropub/vendor/symfony/yaml/Inline.php:209"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "Stack trace:"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#0 /var/www/html/known/micropub/vendor/symfony/yaml/Dumper.php(123): Symfony\Component\Yaml\Inline::dump('slug', 0)"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#1 /var/www/html/known/micropub/vendor/symfony/yaml/Yaml.php(149): Symfony\Component\Yaml\Dumper->dump(Array, 2, 0, 0)"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#2 /var/www/html/known/micropub/nanopub.php(243): Symfony\Component\Yaml\Yaml::dump(Array)"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#3 /var/www/html/known/micropub/nanopub.php(754): write_file(Array, 'test test test', '../content/micr...')"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#4 {main}"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "  thrown in /var/www/html/known/micropub/vendor/symfony/yaml/Inline.php on line 209"
172.17.0.1 -  10/Apr/2018:00:58:13 +0000 "POST /micropub/nanopub.php" 500

YAML: slug value is saved as an array

When writing files using the YAML front matter format, the slug value is returned as an array, i.e.:

slug:
    - my-nanopub-micro-note

As slug is a single value, the expected output is slug: my-nanopub-micro-note.

Check Authorization header case-insensitive.

As noted on the documentation page for getallheaders:

Beware that RFC2616 (HTTP/1.1) defines header fields as case-insensitive entities. Therefore, array keys of getallheaders() should be converted first to lower- or uppercase and processed such.

nanopub currently requires a case-sensitive Authorization. This means it does not work with Omnibear which in my testing sends a lowercased authorization header instead.

nanopub should be accepting all possible cases of the received header.

Uncaught Exception call to Symphony\yaml

Copying from #11

Trying to get nanopub working on a site running PHP7, and getting errors.

php composer.phar install worked:

# php composer.phar install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Package operations: 19 installs, 0 updates, 0 removals
  - Installing guhelski/forecast-php (1.1.1): Downloading (100%)
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
  - Installing guzzlehttp/guzzle (6.3.0): Downloading (100%)
  - Installing j7mbo/twitter-api-php (1.0.6): Downloading (100%)
  - Installing p3k/timezone (0.1.0): Downloading (100%)
  - Installing mf2/mf2 (v0.3.2): Downloading (100%)
  - Installing indieweb/link-rel-parser (0.1.3): Downloading (100%)
  - Installing p3k/http (0.1.5): Downloading (100%)
  - Installing zendframework/zendxml (1.0.2): Downloading (100%)
  - Installing miniflux/picofeed (v0.1.37): Downloading (100%)
  - Installing facebook/graph-sdk (5.6.1): Downloading (100%)
  - Installing ezyang/htmlpurifier (v4.9.3): Downloading (100%)
  - Installing dg/twitter-php (v3.6): Downloading (100%)
  - Installing cebe/markdown (1.1.2): Downloading (100%)
  - Installing p3k/xray (v1.4.2): Downloading (100%)
  - Installing symfony/yaml (v3.4.4): Downloading (100%)
  - Installing tantek/cassis (v0.2.16895): Downloading (100%)
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
mf2/mf2 suggests installing barnabywalters/mf-cleaner (To more easily handle the canonical data php-mf2 gives you)
facebook/graph-sdk suggests installing paragonie/random_compat (Provides a better CSPRNG option in PHP 5)
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
Generating autoload files

I ran the update, as suggested:

# php composer.phar update
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 7 updates, 1 removal
  - Removing miniflux/picofeed (v0.1.37)
  - Updating facebook/graph-sdk (5.6.1 => 5.6.2): Downloading (100%)
  - Installing p3k/picofeed (v0.1.38): Downloading (100%)
  - Updating mf2/mf2 (v0.3.2 => v0.4.3): Downloading (100%)
  - Updating p3k/http (0.1.5 => 0.1.7): Downloading (100%)
  - Updating ezyang/htmlpurifier (v4.9.3 => v4.10.0): Downloading (100%)          - Updating p3k/xray (v1.4.2 => v1.4.23): Downloading (100%)
  - Updating guzzlehttp/guzzle (6.3.0 => 6.3.2): Downloading (100%)
  - Updating symfony/yaml (v3.4.4 => v3.4.8): Downloading (100%)
Writing lock file
Generating autoload files

Here are the errors:

[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Notice:  Undefined index: like_site in /var/www/html/known/micropub/nanopub.php on line 559"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Notice:  Undefined index: repost_site in /var/www/html/known/micropub/nanopub.php on line 573"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Notice:  Undefined index: replysite in /var/www/html/known/micropub/nanopub.php on line 587"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function Symfony\Component\Yaml\ctype_digit() in /var/www/html/known/micropub/vendor/symfony/yaml/Inline.php:209"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "Stack trace:"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#0 /var/www/html/known/micropub/vendor/symfony/yaml/Dumper.php(123): Symfony\Component\Yaml\Inline::dump('slug', 0)"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#1 /var/www/html/known/micropub/vendor/symfony/yaml/Yaml.php(149): Symfony\Component\Yaml\Dumper->dump(Array, 2, 0, 0)"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#2 /var/www/html/known/micropub/nanopub.php(243): Symfony\Component\Yaml\Yaml::dump(Array)"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#3 /var/www/html/known/micropub/nanopub.php(754): write_file(Array, 'test test test', '../content/micr...')"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "#4 {main}"
[10-Apr-2018 00:58:14] WARNING: [pool www] child 13 said into stderr: "  thrown in /var/www/html/known/micropub/vendor/symfony/yaml/Inline.php on line 209"
172.17.0.1 -  10/Apr/2018:00:58:13 +0000 "POST /micropub/nanopub.php" 500

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.