الكلمة الشائعة هي عكس ما أريده. لا أريد أن تحتوي نتائج البحث الخاصة بي على كل تذكرة، بل أريد طريقة للبحث عن تذكرة معينة. لهذا السبب سيكون معرف الموضوع مثاليًا. يتم إنشاؤها تلقائيًا وهي فريدة.
لا، أعتقد أن الكود الذي أستخدمه كان أيضًا من awesomerobot في الأصل، لكن لا يمكنني العثور على مصدره بعد الآن.
أفضل مكان ما أستخدمه حاليًا على تلك الكتلة تحت النص.
حسنًا، لا يمكنني فعل ذلك. ربما يمكنك. أنا أمتلك مجموعة معينة من المهارات. البرمجة ليست من بينها.
أنت تفهمني بشكل خاطئ. كنت أعني وجود كلمة شائعة بما في ذلك المعلمة topic:id، بحيث تظهر النتائج من هذا الموضوع فقط. الكلمة الشائعة تزيل الحاجة إلى تغيير كلمات مثل “مرحباً” و “أهلاً”.
شكراً @NateDhaliwal، أقدر هذا الجهد.
لقد أنشأت المكون، ولصقت الكود تحت علامة تبويب JS. تأكدت من أنه نشط في السمة الخاصة بي، ولكن لم يحدث شيء.
هذا ما تبدو عليه صفحة البحث الخاصة بي:
لدينا حل يعمل. على الرغم من أنه غير أنيق قليلاً، إلا أنه سيفي باحتياجاتي حتى نتمكن من البحث عن معرف الموضوع مباشرة في مربع البحث القياسي.
الكود الحالي الذي اقترحه @awesomerobot يبدو أنه يعمل، ولكنه يؤدي إلى ظهور التحذير الذي نشرته أعلاه.
2أ. عندما قمت بإزالة الكود الأصلي الذي كنت أستخدمه لعرض معرف الموضوع، اختفى هذا التحذير…
عندما تختار حلاً، يظهر الكود لعرض معرف الموضوع في كل من المنشور الأصلي وفي الحل، هل هناك طريقة لمعالجة ذلك ومنعه من الظهور هناك؟
قمت بتزيين CSS قليلاً، الآن لدي حبوب على كل رد في كل سلسلة في الفئات المحددة التي أستخدمها فيها. أفترض أن الإجابة ستكون إلغاء التزيين، ولكن إذا عرف أي شخص طريقة أخرى، أفضل الاحتفاظ بها، أعتقد أنها تبدو لطيفة كما هي.
@awesomerobot
يعمل الكود الخاص بك بشكل رائع، ولكن يبدو أن أي زخارف CSS بخلاف النص تظهر في كل مشاركة بعد الأولى كمساحة فارغة منسقة بالطريقة التي تقولها CSS.
قم بإيقاف تشغيل الكتلة المضمنة وستحصل على شريط ألوان بعرض كامل.
قم بتغيير لون الخلفية وسيتغير لون الحبة
إلخ…
بناءً على ما كتبته، يبدو أنك أخبرته أن يظهر فقط في المنشور الأول، ولكن هذا يؤثر فقط على النص. هل هناك أي شيء آخر يمكننا فعله لقتل العنصر في جميع المشاركات الإضافية؟
حسنًا، كما قلت، أنا لست مبرمجًا، ولكني بارع جدًا في طرح الأسئلة على Grok. إليك رمز يعالج كلا المشكلتين.
لا مزيد من فقاعات CSS الفارغة في الردود من 2 إلى X.
لا مزيد من تكرار معرف الموضوع في الحلول المقتبسة.
ربما لا يهتم أي شخص آخر على وجه الأرض، ولكن هذا يبدو طريقة جيدة للمساعدة في تتبع الموضوعات لأولئك منا الذين يستخدمون Discourse كنظام تذاكر.
import { apiInitializer } from "discourse/lib/api";
import Component from "@glimmer/component";
class TopicIdentifier extends Component {
get topicId() {
return this.args.post?.topic?.id;
}
get shouldShow() {
const firstPost = this.args.post?.post_number === 1; // first post in topic
const desiredCategories = [9, 23]; // a comma separated list of category IDs you want this to appear in
const isInCategory = desiredCategories.includes(
this.args.post?.topic.category.id
);
return firstPost && isInCategory;
}
<template>
{{#if this.shouldShow}}
<!-- you can edit the content below, {{this.topicId}} is where the topic ID will be filled -->
Issue Tracking # is
{{this.topicId}}
<!-- you can edit the content above -->
{{/if}}
</template>
}
export default apiInitializer("0.8.40", (api) => {
api.decorateCookedElement((element, helper) => {
```gjs
import { apiInitializer } from "discourse/lib/api";
import Component from "@glimmer/component";
class TopicIdentifier extends Component {
get topicId() {
return this.args.post?.topic?.id;
}
get shouldShow() {
const firstPost = this.args.post?.post_number === 1; // first post in topic
const desiredCategories = [9, 23]; // a comma separated list of category IDs you want this to appear in
const isInCategory = desiredCategories.includes(
this.args.post?.topic.category.id
);
return firstPost && isInCategory;
}
<template>
{{#if this.shouldShow}}
<!-- you can edit the content below, {{this.topicId}} is where the topic ID will be filled -->
Issue Tracking # is
{{this.topicId}}
<!-- you can edit the content above -->
{{/if}}
</template>
}
export default apiInitializer("0.8.40", (api) => {
api.decorateCookedElement((element, helper) => {
// Only proceed if this is the first post and not inside a solution quote
// Only proceed if this is the first post, not in a quote, and in the desired category
const post = helper?.model;
const desiredCategories = [9, 23]; // Match the categories from TopicIdentifier
if (
if (
helper?.model?.post_number !== 1 ||
!post ||
post.post_number !== 1 ||
!desiredCategories.includes(post.topic?.category?.id) || // Check category
element.classList.contains("post__contents-cooked-quote") || // Check if the element itself is the quote content
element.closest("aside.accepted-answer") || // Check for solution/quote wrapper
element.closest(".quote") // Additional check for generic quotes
) {
return;
}
const wrapper = document.createElement("div");
wrapper.className = "tracking-id";
helper?.renderGlimmer(
wrapper,
<template><TopicIdentifier @post={{helper.model}} /></template>
);
element.appendChild(wrapper);
});
});
أعلم أنه يمكنني اختباره بسهولة، ولكن هل تعرف على الفور ما إذا كان هذا سيعمل إذا وضعت هذا الـ JS والـ CSS في مكون خاص به، أم يجب أن يكون في السمة نفسها؟
لقد وجدت شذوذًا صغيرًا آخر. كنت أرى فقاعات الفئة الفارغة في المنشور الأول للمواضيع خارج الفئتين اللتين أردتهما فيهما، لذلك اضطررت إلى تحديث الكود قليلاً. إليك المنتج النهائي.
import { apiInitializer } from "discourse/lib/api";
import Component from "@glimmer/component";
class TopicIdentifier extends Component {
get topicId() {
return this.args.post?.topic?.id;
}
get shouldShow() {
const firstPost = this.args.post?.post_number === 1; // first post in topic
const desiredCategories = [9, 23]; // a comma separated list of category IDs you want this to appear in
const isInCategory = desiredCategories.includes(
this.args.post?.topic.category.id
);
return firstPost && isInCategory;
}
<template>
{{#if this.shouldShow}}
<!-- you can edit the content below, {{this.topicId}} is where the topic ID will be filled -->
Issue Tracking # is
{{this.topicId}}
<!-- you can edit the content above -->
{{/if}}
</template>
}
export default apiInitializer("0.8.40", (api) => {
api.decorateCookedElement((element, helper) => {
// Only proceed if this is the first post and not inside a solution quote
// Only proceed if this is the first post, not in a quote, and in the desired category
const post = helper?.model;
const desiredCategories = [9, 23]; // Match the categories from TopicIdentifier
if (
if (
helper?.model?.post_number !== 1 ||
!post ||
post.post_number !== 1 ||
!desiredCategories.includes(post.topic?.category?.id) || // Check category
element.classList.contains("post__contents-cooked-quote") || // Check if the element itself is the quote content
element.closest("aside.accepted-answer") || // Check for solution/quote wrapper
element.closest(".quote") // Additional check for generic quotes
) {
return;
}
const wrapper = document.createElement("div");
wrapper.className = "tracking-id";
helper?.renderGlimmer(
wrapper,
<template><TopicIdentifier @post={{helper.model}} /></template>
);
element.appendChild(wrapper);
});
});
element.classList.contains("post__contents-cooked-quote") || // Check if the element itself is the quote content
element.closest("aside.accepted-answer") || // Check for solution/quote wrapper
element.closest(".quote") // Additional check for generic quotes
) {
return;
}
const wrapper = document.createElement("div");
wrapper.className = "tracking-id";
helper?.renderGlimmer(
wrapper,
<template><TopicIdentifier @post={{helper.model}} /></template>
);
element.appendChild(wrapper);
});
});
وللإجابة على سؤالي بنفسي، قمت بنقل كل الكود إلى مكون سمة جديد وكل شيء لا يزال يعمل بشكل جيد.