• hi again, thanks for the plugin, it is VERY useful.

    Topic: new feature

    I already submitted this idea and mentioned how relevant it is but I promise this is my last try.

    • context:
    • Your default image slug is “word-image”. It is applied when images in the document have no altText. This is the case for 99% of documents, as people just don’t care for images altText within a Word document, sorry.
      Users of your plugin end up having tons of images named “word-image-[num].*” in their upload folders. This doesn’t help for future Media Library management. We don’t know which image belongs to which post.

    • proposition:
    • I would be nice to setup a default slug with at least the post ID, and also let users setup their own image slug value. It is easy to implement as I give you the code below:

    • mammoth-docx-converter.php
    • lines 74-75:

      
                  <p>Images slug pattern: <input type="text" id="mammoth-docx-image-slug" name="word-image-<?php echo $post->ID; ?>" value="word-image-<?php echo $post->ID; ?>" /></p>
                  <p>Override image altText: <input type="checkbox" id="mammoth-docx-image-slug-override" value="true" /></p>
      
    • mammoth-editor.js
    • function generateFilename(options)

      
          function generateFilename(options) {
      		// by default the image slug will be word-image-postID
      		var slugDefault = document.getElementById('mammoth-docx-image-slug').name;
      		// security if user leaves input empty
      		var slugCustom = (document.getElementById('mammoth-docx-image-slug').value.length == 0) ? slugDefault : document.getElementById('mammoth-docx-image-slug').value;
      		var slugOverride = document.getElementById('mammoth-docx-image-slug-override').checked;
      		var name = options.altText ? slug(options.altText.slice(0, 50), slugOptions) : slugCustom;
      		// if slugOverride is checked the image slug will be slugCustom even if altText is found
      		name = (slugOverride) ? slugCustom : name;
              var extension = options.contentType.split("/")[1];
              return name + "." + extension;
          }
      

    I tested it with documents using images w/ and w/o altText and everything works as intended.
    No hurry, but please I would be grateful if you would update your code for the next version. I am tired of having to update your plugin by hand after each update ??

  • The topic ‘new feature: use your own image slug and use post ID as default’ is closed to new replies.