typemill / typemill

Typemill is a lightweight, flat-file CMS designed for simple, fast, and flexible website and eBook creation using Markdown.
https://typemill.net
MIT License
427 stars 60 forks source link

New plugin counter #191

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi trendschau, I just uploaded a new plugin, counter.

Its function is to display on the publish-controller bar the counters of the characters, words, sentences and reading time of the page currently being edited. It works both in raw and in visual.

To be honest, in visual it only works if an event is emitted that you have already used yourself: eventBus. So I need vue-blox.js to be added to lines 650, 890 and 916 (for now I have limited the count to the markdown, olist and ulist components only):

eventBus.$emit('updatedMarkdown', value);

Try it yourself, when you have time :-)

If you have any suggestions on how to intercept the event differently, let me know.

NB: The URL that appears in the GIF contains a typemill-1.3.7: read it as 1.3.8 because I have updated to the latest version.

trendschau commented 3 years ago

Great!! I will have a look and provide feedback when I am back in office next week :)

trendschau commented 3 years ago

Hi Iusvar,

I had a short look into the code but I did not had the time to test it in depth. I think we should search for a more general solution to hack into the events, otherwise I have to add code to the core of Typemill for each plugin and that does not feel very clean. I am sure there is a way to fire a general event on change or on input that other plugins can listen to.

I will try to find a solution for the next release, currently working on it and I hope to publish it end of August. Is that fine for you?

Cheers, Sebastian

ghost commented 3 years ago

hi, I totally agree. See you soon.

trendschau commented 3 years ago

sorry, I was totally blocked with other stuff, but I will start now to work on the open tasks :)

ghost commented 3 years ago

no problem, thank you

I myself have not deepened yet but ... I think an easy solution could be to use an event bus in a generalized way. Besides in vue-blox.js you already use it for "closeComponents" :)

trendschau commented 3 years ago

Hey jusvar,

I checked it now but I need your help with this. As you suggested I used the eventBus and simply fired a new event "markdownChanged" each time when the markdown is updated. I added this event to the contentComponent in vue-blox.js in the method updateMarkdown:

        updateMarkdown: function($event)
        {
            eventBus.$emit('markdownChanged');
            this.compmarkdown = $event;
            this.setComponentSize();
        },

This event fires now nearly every time when the user changes any content. I tested it with a little test-component like this:

const counter = Vue.component('counter', {
    data: function () {
        return {
            counter: 1,
        }
    },
    template: '<div class="counter">{{counter}}</div>',
    mounted: function()
    {
        eventBus.$on('markdownChanged', this.countMarkdown);
    },
    methods: {
        countMarkdown: function(event)
        {
            this.counter = this.counter+1; 
        },
    },
});

Is that enough for your plugin? I can add some more events if you need them or pass some data with the event. I could not check the requirements of your plugin because there is pretty much code, so it would take quite some time to understand everything :D

Can you check it and provide some feedback?

ghost commented 3 years ago

Hi trendschau, I will give you feedback asap, thanks

ghost commented 3 years ago

Hi trendschau,

I'm there, the new markdownChanged event is fine but I would need the $event argument passed.

So like this

        updateMarkdown: function($event)
        {
            eventBus.$emit('markdownChanged',$event);
            this.compmarkdown = $event;
            this.setComponentSize();
        },

Thank you

trendschau commented 3 years ago

Hi iusvar, published with version 1.4.0, please try and let me know when I should publish your plugin on the plugin page...

ghost commented 3 years ago

Hi trendschau, as far as listening to the event is concerned, everything is fine. As far as publication is concerned, I still have to work on it to make it really work. I'll let you know when I'm done. Thank you.