Coder Social home page Coder Social logo

jeremyfelt / shortnotes Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 1.0 3.14 MB

Add a notes post type to WordPress. For your short notes.

Home Page: https://wordpress.org/plugins/shortnotes/

License: Other

PHP 82.80% JavaScript 4.74% Shell 12.46%
wordpress plugin indieweb webmention

shortnotes's Introduction

Shortnotes

Add a notes post type to WordPress. For your short notes.

Description

Shortnotes adds a custom post type, Notes, used to publish short pieces of content on your website, similar to social networks like Mastodon, Twitter, or Instagram.

No titles

The Notes post type does not support traditional titles.

Note titles are not generally meant to be displayed as part of the theme layout. You will likely need to adjust the look and feel of your theme accordingly. See the Theme Customization section below for more details.

A title is generated automatically from note content and is used as the note's document title. This is readable by search engines and displayed in browser tabs.

Limited blocks

The Notes post type supports basic content blocks like paragraph, list, quote, image, preformatted text, gallery, video, and embed. Using a defined list of relatively simple blocks helps to keep notes simple.

Webmention support

The Notes post type includes support for the Webmention and Semantic-Linkbacks plugins.

URLs in note content are processed as possible webmentions.

A panel in the block editor allows for the addition of a reply to URL and name. When entered, they are used to provide markup for a semantic webmention reply.

Reply to template tag

The reply specification works best when the u-in-reply-to element is outside of the main content element, defined by e-content.

A template tag is provided as part of the Shortnotes plugin that can be used to output reply to markup in your theme.

<article class="h-entry">
	<?php
	if ( function_exists( 'ShortNotes\PostType\Note\reply_to_markup' ) ) {
		\ShortNotes\PostType\Note\reply_to_markup();
	}
	?>
	<div class="entry-content e-content">
		<?php the_content(); ?>
	</div><!-- .entry-content -->
</article>

If this template tag is not used, then the Shortnotes plugin will automatically prepend the reply to markup to the_content.

Theme Customization

No customization of your theme is required to use this plugin, though you will likely want to think through how titles are displayed and if you want full support for webmentions.

If you do find yourself wanting to customize, I have made adjustments to my site's theme, a child theme of Twenty Twenty One, while developing this plugin, that can be used as an example.

Those adjustments (a) remove the display of a title for the note post type and (b) output reply to markup outside of the main content element.

Changelog

1.6.2

  • Fix an issue when prepending reply markup to content during an oembed request. Thanks jorbin!
  • Update @wordpress/scripts dependency to 26.15.0.
  • Add phpstan configuration.
  • Remove old, unnecessary pre-PHP 5.6 notice.
  • Confirm upcoming WordPress 6.4 support.

1.6.1

  • Remove vendor/ directory from distribution.

1.6.0

  • Improve title generation when a note starts with a quote.
  • Improve text formatting of notes posted to Mastodon through Share on Mastodon:
    • Avoid duplicate dashes when a note with a quote is transformed for Mastodon.
    • Remove leading and trailing double quotes of all flavors when a note with a quote is transformed for Mastodon.
    • Ensure persisting line breaks for preformatted blocks with <br> tags.
    • Improve handling of lists and list items when transforming content for Mastodon.
  • Update @wordpress/scripts dependency to 26.8.0.

1.5.0

  • Improve text formatting of notes posted to Mastodon through Share on Mastodon:
    • Transform quote block to a text representation of the quote and citation.
    • Transform embed blocks to a raw URL.
    • Improve transformation of paragraph blocks.
    • Improve extraction of anchor hrefs from markup.
  • Properly reply to a previous note's corresponding Mastodon post.
  • Remove hacky filtering of Share on Mastodon.
    • This is technically a back-compat break for Share on Mastodon <0.9.
  • Use the quote block to generate a note title, if available.
  • Update @wordpress/scripts dependency to 25.5.1.

1.4.0

  • Integrate with Share on Mastodon plugin to send notes to Mastodon:
    • Full note text is sent to Mastodon with stripped HTML.
    • If a repy to URL is a Mastodon post, it will appear as a reply in Mastodon.
  • Fix an issue where titles did not generate as expected on scheduled notes.
  • Update @wordpress/scripts dependency to 24.6.0.
  • Confirm WordPress 6.1 support.

1.3.1

  • Update @wordpress/scripts dependency to 23.2.0.
  • Confirm WordPress 6.0 support.

1.3.0

  • Add a shortnotes_post_type_arguments filter.
  • Fix a minor documentation issue.
  • Update @wordpress/scripts dependency to 23.0.0.

1.2.0

  • Fix a bug in title generation when an image block is followed by a paragraph.
  • Start tracking note type: note or reply.
  • Improve reply-to interface to appear only when the note type is a reply.
  • Update @wordpress/scripts dependency to 22.3.0.

1.1.5

  • Introduce common function to generate a shortnote's subtitle.
  • Parse non-Gutenberg HTML blocks for possible sub title content.

1.1.4

  • Add shortnotes_formatted_title filter to allow for additional title filtering elsewhere.

1.1.3

  • Stop editor from crashing when a note is saved in Gutenberg 11.4.0+.

1.1.2

  • Add shortnotes_reply_to_name filter.
  • Update @wordpress/scripts dependency to 19.2.2.
  • Rebuild JavaScript asset with latest WP scripts.

1.1.1

  • Confirm support for WordPress 5.8.
  • Update @wordpress/scripts dependency to 17.0.0.
  • Rebuild JavaScript asset with latest WP scripts.
  • Remove unused get_version() function before it's too late!

1.1.0

  • Add support for more simple core blocks: video, file, embed, etc...
  • Fix overeager loading of plugin assets on post types that are not shortnote.

1.0.2

  • Fix display of "(no title) is now live." in block editor when new note is published.

shortnotes's People

Contributors

jeremyfelt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

peterwilsoncc

shortnotes's Issues

Add full support for requests handled by Micropub

The Micropub plugin for WordPress handles Micropub requests to WordPress sites.

Right now, these incoming requests are stored as posts and post_content is built from the request to contain the correct microformats. If the Post Kinds plugin is active, then it will perform some actions based on these requests so that posts are treated as replies, bookmarks, etc...

On my site, which is the primary feature driver of the Shortnotes plugin, I would like to route Micropub requests so that they are stored as the shortnote post type instead. There should probably be some awareness of the Post Kinds plugin in the rare case that both are active.

In a first iteration, I think:

  • Notes, Replies, and Bookmarks should be stored as short notes.
  • Micropub's rendering of this content should be removed and provided by Shortnotes.
  • Rendered content should be block editor compatible.
  • Rendered content should be microformat compatible.
  • The block editor UI for Shortnotes should support any fields captured via Micropub.

There's probably more, but that's a good start!

TypeError: ShortNotes\PostType\Note\get_reply_to_markup(): Argument #1 ($post) must be of type WP_Post, null given, called in /var/www/html/wp-content/plugins/shortnotes/includes/post-type-note.php on line 383

This seems to happen on oembed requests. For example, https://aaron.jorb.in/wp-json/oembed/1.0/embed?url=https%3A%2F%2Faaron.jorb.in%2Ftransparent-salaries-in-wordpress%2F which currently triggers a fatal error.

Full stack trace:

TypeError: ShortNotes\PostType\Note\get_reply_to_markup(): Argument #1 ($post) must be of type WP_Post, null given, called in /var/www/html/wp-content/plugins/shortnotes/includes/post-type-note.php on line 383
(/var/www/html/wp-content/plugins/shortnotes/includes/post-type-note.php:315)

ShortNotes\PostType\Note\get_reply_to_markup(/var/www/html/wp-content/plugins/shortnotes/includes/post-type-note.php:383)

ShortNotes\PostType\Note\prepend_reply_to_markup(/var/www/html/wp-includes/class-wp-hook.php:324)

WP_Hook::apply_filters(/var/www/html/wp-includes/plugin.php:205)

apply_filters(/var/www/html/wp-includes/formatting.php:3992)

wp_trim_excerpt(/var/www/html/wp-includes/class-wp-hook.php:324)

WP_Hook::apply_filters(/var/www/html/wp-includes/plugin.php:205)

apply_filters(/var/www/html/wp-includes/post-template.php:434)

get_the_excerpt(/var/www/html/wp-content/plugins/wordpress-seo/src/helpers/post-helper.php:84)

Yoast\WP\SEO\Helpers\Post_Helper::get_the_excerpt(/var/www/html/wp-content/plugins/wordpress-seo/src/presentations/indexable-post-type-presentation.php:196)

Yoast\WP\SEO\Presentations\Indexable_Post_Type_Presentation::generate_open_graph_description(/var/www/html/wp-content/plugins/wordpress-seo/src/presentations/abstract-presentation.php:66)

Yoast\WP\SEO\Presentations\Abstract_Presentation::__get(/var/www/html/wp-content/plugins/wordpress-seo/src/presenters/open-graph/description-presenter.php:33)

Yoast\WP\SEO\Presenters\Open_Graph\Description_Presenter::get(/var/www/html/wp-content/plugins/wordpress-seo/src/surfaces/values/meta.php:205)

Yoast\WP\SEO\Surfaces\Values\Meta::__get(/var/www/html/wp-content/plugins/wordpress-seo/src/integrations/front-end/open-graph-oembed.php:116)

Yoast\WP\SEO\Integrations\Front_End\Open_Graph_OEmbed::set_description(/var/www/html/wp-content/plugins/wordpress-seo/src/integrations/front-end/open-graph-oembed.php:94)

Yoast\WP\SEO\Integrations\Front_End\Open_Graph_OEmbed::set_oembed_data(/var/www/html/wp-includes/class-wp-hook.php:326)

WP_Hook::apply_filters(/var/www/html/wp-includes/plugin.php:205)

apply_filters(/var/www/html/wp-includes/embed.php:609)

get_oembed_response_data(/var/www/html/wp-includes/class-wp-oembed-controller.php:132)

WP_oEmbed_Controller::get_item(/var/www/html/wp-includes/rest-api/class-wp-rest-server.php:1193)

WP_REST_Server::respond_to_request(/var/www/html/wp-includes/rest-api/class-wp-rest-server.php:1041)

WP_REST_Server::dispatch(/var/www/html/wp-includes/rest-api/class-wp-rest-server.php:431)

WP_REST_Server::serve_request(/var/www/html/wp-includes/rest-api.php:424)

rest_api_loaded(/var/www/html/wp-includes/class-wp-hook.php:324)

WP_Hook::apply_filters(/var/www/html/wp-includes/class-wp-hook.php:348)

WP_Hook::do_action(/var/www/html/wp-includes/plugin.php:565)

do_action_ref_array(/var/www/html/wp-includes/class-wp.php:418)

WP::parse_request(/var/www/html/wp-includes/class-wp.php:813)

WP::main(/var/www/html/wp-includes/functions.php:1336)

wp(/var/www/html/wp-blog-header.php:16)

require(/var/www/html/index.php:17)

Add support for other very simple core blocks

I was originally thinking core/video, core/file, and core/embed. I'm now thinking about all of the other basic text blocks.

I think the guiding thought here is: stick to blocks that do not provide much additional formatting, but that are meant for adding specific pieces of content.

Allow lists and list items

  • It seems really hard to add more than one list item when creating a note
  • The list gets removed from content when posted to Mastodon
  • The list markup is broken when posted as a webmention reply (which might be okay)

Add option to change post type to post

While writing a short note, you may find yourself wanting it to be a full post (or something else) instead. It's easy enough to copy and paste everything, but it'd be even cooler if you could quickly convert it.

Introduce filter to allow limiting filter_status_text to certain post types.

This filter_status_text method filters the default text when sharing to mastondon to use the content of the post.

/**
* Filter a toot so that the note content is used rather than the title.
*
* @param string $status The status text.
* @param \WP_Post $post The post object.
* @return string The modified status text.
*/
function filter_status_text( string $status, \WP_Post $post ): string {
$status = Note\transform_content( $post->post_content );
return $status;
}

Unfortunately it's a little blunt and filters the text for all post types, be that posts, pages, or shortnotes.

A filter to allow other plugins to remove bypass the modification with ease would be most helpful. It can be done with a little work but it's a little unwieldy and probably flakey:

add_filter( 'share_on_mastodon_status', __NAMESPACE__ . '\\share_on_mastodon_status_text', 9, 2 );function share_on_mastodon_status_text( $status, $post ) {
	if ( ! in_array( $post->post_type, array( 'shortnote', 'pwcc_notes' ), true ) ) {
		// Remove Jeremy's filter.
		remove_filter( 'share_on_mastodon_status', 'ShortNotes\\ShareOnMastodon\\filter_status_text', 10 );
	}

	return $status;
}

I suggest a simple preflight filter of some description:

/**
 * Filter to bypass modification of default sharing text.
 * 
 * @param bool $bypass Whether to bypass the modifying text. Default false.
 * @param string $status The default status. 
 * @param \WP_Post $post The post being shared.
 */
$bypass = apply_filter( 'shortnotes_pre_modify_status_text', false, $status, $post );

if ( $bypass === true ) {
    return $status;
}

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.