Comments (5)
@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' && (
<>
—
<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.
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.
@edtorba this was just released in 1.0.11
🎉
from plugin-seo.
Hey 👋 Is it supposed to be something like this?
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 && (
<>
—
<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.
Am on 1.0.10 and it's still showing 👀
My config:
seo({
collections: [
'pages',
],
uploadsCollection: 'media',
},
),
from plugin-seo.
Related Issues (20)
- Are Translations Supported? HOT 1
- Re-Use fancy Min/Max Lenght for other fields HOT 1
- Tabbed UI breaks position 'sidebar' HOT 3
- Validation issue on save HOT 4
- Disable tabs nesting HOT 2
- Search by ID only with tabbedUI: true HOT 3
- Display added alt/title on Media when used HOT 1
- Text cursor jumps to end of content HOT 1
- Feat request: Add focus keywords or keyphrase HOT 1
- forms_1.useAllFormFields is not a function HOT 2
- TabbedUI breaks content fields with `position: 'sidebar'` HOT 11
- Next-Payload not working together with plugin-seo HOT 13
- Allow custom more fields in SEO group? HOT 4
- Nothing displaying in admin panel HOT 2
- Add opengraph support HOT 2
- Fields not rendering in collection when SEO is enabled since v1.0.12 HOT 4
- How to access collection slug inside `generateURL`? HOT 4
- Input is broken on latest payload HOT 1
- Using S3 Adapter, og:image + twitter:image set to SITE_URL/S3_IMAGE_URL HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plugin-seo.