Giter Site home page Giter Site logo

Comments (5)

jacobsfletch avatar jacobsfletch commented on June 11, 2024 1

@dragos199993 that's pretty much it but to make this much simpler just add that condition directly to the JSX and don't use state, like this:

{typeof generateTitle === 'function' && (
  <>
    &nbsp; &mdash; &nbsp;
    <button
      onClick={regenerateTitle}
      type="button"
      style={{
        padding: 0,
        background: "none",
        border: "none",
        backgroundColor: "transparent",
        cursor: "pointer",
        textDecoration: "underline",
        color: "currentcolor",
      }}
    >
      Auto-generate
    </button>
  </>
)}

I'd happily merge a PR if you wanted to give this a shot!

from plugin-seo.

jacobsfletch avatar jacobsfletch commented on June 11, 2024 1

Hey @edtorba looks like this PR was merged in but not released. I'll cut a new release for this as soon as possible.

from plugin-seo.

jacobsfletch avatar jacobsfletch commented on June 11, 2024 1

@edtorba this was just released in 1.0.11 🎉

from plugin-seo.

dragos199993 avatar dragos199993 commented on June 11, 2024

Hey 👋 Is it supposed to be something like this?
image

Did a fix on MetaTitle, but wanted to be sure this is the correct approach. If I get the green light from one of the maintainers I can open a PR.

The solution will be to check in each component: MetaTitle, MetaDescription and MetaImage if we have value on the field.
This can be achieved by using a useState and an useEffect that updates this value based on the generate* function response:

const [fieldVisible, setFieldVisible] = useState(false);

    const { generateTitle } = pluginConfig;

    if (typeof generateTitle === "function") {
      setFieldVisible(!!(await generateTitle({ doc: { ...fields }, locale })));
    }
  }, []);

After that we only add the "if statement" in JSX to disable the Auto-generate button:

{fieldVisible && (
            <>
              &nbsp; &mdash; &nbsp;
              <button
                onClick={regenerateTitle}
                type="button"
                style={{
                  padding: 0,
                  background: "none",
                  border: "none",
                  backgroundColor: "transparent",
                  cursor: "pointer",
                  textDecoration: "underline",
                  color: "currentcolor",
                }}
              >
                Auto-generate
              </button>
            </>
          )}

However since this logic will be repeated, maybe it can be extracted in a small custom hook?

from plugin-seo.

edtorba avatar edtorba commented on June 11, 2024

Am on 1.0.10 and it's still showing 👀
My config:

seo({
    collections: [
      'pages',
    ],
    uploadsCollection: 'media',
  },
),
Screenshot 2023-05-13 at 11 54 17

from plugin-seo.

Related Issues (20)

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.