notum-cz / strapi-plugin-content-versioning

This plugin enables content versioning in Strapi
129 stars 46 forks source link

Redirecting to latest version #31

Open ScottPenhall98 opened 2 years ago

ScottPenhall98 commented 2 years ago

Description

Hey guys, really love your package. Still a bit of a ways to got but getting there. I was trying to implement my own redirects, as currently, the shown version displays the Published page, I was trying to set it so when a versioned type is clicked in Content Manager. it would display the most recent version by forcing a redirect, which is how most of our CMS's work.

Is there any way you could recommend how I approach this?

Code snippets

So, I made some middleware that does almost exactly what I want. Only problem is when you redirect within selecting a react link it doesn't do a proper redirect. It will just replace the content of what is in the text fields, which works.... until you select publish. here's the middleware code.

module.exports = (config, {strapi}) => {
  return async (ctx, next) => {
    if (ctx.url.includes('/content-manager/single-types')) {
      const dataVersions = ctx.response.body.versions;
      if (dataVersions && dataVersions.length > 1) {
        let newestVersion;
        dataVersions.forEach(version => {
          if (!newestVersion || newestVersion.versionNumber < version.versionNumber) {
            newestVersion = version;
          }
        });
        ctx.redirect('/admin/content-manager/collectionType/api::about-content.about-content/' + newestVersion.id);
      }
    }
  }
};

Any other suggestions or recommendations are welcome

omikulcik commented 1 year ago

Hey @ScottPenhall98, it would certainly be more convenient to have the most recent version displayed and thank you for proposing it. However, we will consider implementing this later as we currently have more important issues to solve.