### Start Discourse Server Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Starts the Discourse development server to test the plugin locally. ```bash bin/rails server ``` -------------------------------- ### Install Plugin via Git Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/README.md Use this command to clone the plugin repository into your Discourse instance and rebuild the application. ```bash cd /var/discourse git clone https://github.com/kaktaknet/discourse-rich-json-ld-microdata.git plugins/discourse-rich-json-ld-microdata ./launcher rebuild app ``` -------------------------------- ### Install Plugin Dependencies Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Installs the necessary Ruby gems for the plugin using Bundler. ```bash bundle install ``` -------------------------------- ### Verify Plugin Installation Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Verify the plugin is working by checking for the 'data-rich-microdata' attribute in the page source. ```html ``` -------------------------------- ### Server Translations Example (French) Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Provides an example of server-side translations in French for site settings and various plugin components like breadcrumbs, Open Graph, Twitter Cards, profile pages, and interaction statistics. ```yaml fr: site_settings: rich_microdata_enabled: "Activer le plugin Rich Microdata" rich_microdata_cache_ttl: "Durée du cache en secondes" # ... more settings discourse_rich_microdata: breadcrumb: home: "Accueil" open_graph: category_description: "Discussions dans %{category_name}" user_description: "Profil de %{user_name}" twitter_card: label_replies: "Réponses" label_author: "Auteur" label_topics: "Sujets" label_posts: "Messages" label_karma: "Karma" profile_page: title: "Profil de %{user_name}" interaction_stats: created_topics: "Sujets créés" written_replies: "Réponses écrites" received_likes: "J'aime reçus" read_posts: "Messages lus" number_of_topics: "Nombre de sujets" number_of_replies: "Nombre de réponses" ``` -------------------------------- ### Test Specific Builder in Rails Console Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Example of how to instantiate and build output for a specific builder (e.g., `QAPageBuilder`) with sample data in the Rails console. ```ruby data = { title: "Test", posts: [...] } builder = DiscourseRichMicrodata::Builders::QAPageBuilder.new(data, {}) puts JSON.pretty_generate(builder.build) ``` -------------------------------- ### Update CHANGELOG.md for Release Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Example of how to update the CHANGELOG.md file with new version information, including the version number, release date, and a summary of changes. ```markdown ### Version 2.1.0 (2025-01-20) - ✨ Added X feature - 🐛 Fixed Y bug - 📚 Improved Z documentation ``` -------------------------------- ### Discourse Solved Plugin Integration Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Example demonstrating how the plugin detects and includes accepted answers in the QAPage schema when integrated with the Discourse Solved plugin. ```ruby # When topic has accepted answer topic = Topic.find(123) topic.custom_fields['accepted_answer_post_id'] # => 5 # Generated QAPage includes acceptedAnswer result = MetaGeneratorService.generate_for_topic(topic) schema = JSON.parse(result[:body].match(/)' | \ python -m json.tool ``` -------------------------------- ### Generate Meta Markup for Topic Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Generates Open Graph and JSON-LD schemas for a topic. Requires a Topic object as input. ```ruby topic = Topic.find(123) result = MetaGeneratorService.generate_for_topic(topic) puts result[:head] # Open Graph + Twitter Cards puts result[:body] # JSON-LD schemas ``` -------------------------------- ### Manually Generate Schema Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Manually trigger the generation of schema markup for a specific topic using `MetaGeneratorService`. Useful for debugging markup generation issues. ```ruby topic = Topic.find(123) result = MetaGeneratorService.generate_for_topic(topic) puts result ``` -------------------------------- ### Ruby Commenting Standards Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Illustrates good and bad practices for commenting Ruby code. Focus on commenting complex logic only and avoiding commented-out code. ```ruby # Calculate final score using weighted average of likes and views score = (likes * 0.7) + (views * 0.3) / total_interactions ``` ```ruby # This is the score score = (likes * 0.7) + (views * 0.3) / total_interactions # calculate score ``` -------------------------------- ### Create Locale Files for New Languages Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/README.md To add new languages, create server and client locale files in the config/locales directory. ```yaml config/locales/ ├── server.es.yml # Spanish backend ├── client.es.yml # Spanish frontend ``` -------------------------------- ### Configure Rich Microdata Plugin Settings Source: https://context7.com/kaktaknet/discourse-rich-json-ld-microdata/llms.txt Access and modify plugin settings via SiteSetting. Use these settings to control the behavior and output of the Rich Microdata plugin. ```ruby # Enable/disable plugin SiteSetting.rich_microdata_enabled # => true (default) # Content type determines Schema.org type SiteSetting.rich_microdata_content_type # => "discussion" (options: discussion, qa, article, news, review, recipe, event) # Maps to: DiscussionForumPosting, QAPage, Article, NewsArticle, Review, Recipe, Event # Cache TTL in seconds SiteSetting.rich_microdata_cache_ttl # => 3600 (default, range: 300-86400) # Limits for included content SiteSetting.rich_microdata_max_answers # => 10 (default, range: 5-50) SiteSetting.rich_microdata_max_comments # => 5 (default, range: 0-20, nested comments per answer) # Include user statistics in Person schema SiteSetting.rich_microdata_include_user_stats # => true (default) # Enable BreadcrumbList schema SiteSetting.rich_microdata_enable_breadcrumbs # => true (default) # Enable WebSite schema with SearchAction SiteSetting.rich_microdata_enable_website_schema # => true (default) # Default Open Graph image when topic has no image SiteSetting.rich_microdata_og_image_default # => "" (absolute URL or empty for site logo) # Alternate locales for og:locale:alternate (comma-separated) SiteSetting.rich_microdata_og_alternate_locales # => "" (e.g., "en_US, zh_CN") # Social media links for Organization schema sameAs SiteSetting.rich_microdata_social_twitter # @handle or URL SiteSetting.rich_microdata_social_facebook # Page URL SiteSetting.rich_microdata_social_youtube # Channel URL SiteSetting.rich_microdata_social_instagram # Profile URL SiteSetting.rich_microdata_social_telegram # Channel URL SiteSetting.rich_microdata_social_linkedin # Company URL SiteSetting.rich_microdata_social_vk # Page URL SiteSetting.rich_microdata_social_dzen # Channel URL SiteSetting.rich_microdata_social_tiktok # Profile URL SiteSetting.rich_microdata_social_tenchat # Profile URL # Repository links SiteSetting.rich_microdata_repo_github # Organization URL SiteSetting.rich_microdata_repo_gitlab # Organization URL SiteSetting.rich_microdata_repo_sourcecraft # Organization URL SiteSetting.rich_microdata_repo_bitbucket # Organization URL # Debug and validation SiteSetting.rich_microdata_debug_mode # => false (enables debug logging) SiteSetting.rich_microdata_validate_output # => false (validates JSON-LD against Schema.org - development only) ``` -------------------------------- ### Generate Meta Tags in Rails Console Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Demonstrates how to use the MetaGeneratorService within the Rails console to generate meta tags for a specific topic. ```ruby # Rails console topic = Topic.find(123) result = MetaGeneratorService.generate_for_topic(topic, nil, nil) puts result[:head] puts result[:body] ``` -------------------------------- ### Test Open Graph Builder Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Tests the Open Graph builder by extracting topic data and building the Open Graph tags. Allows specifying language. ```ruby topic = Topic.find(123) data = DiscourseRichMicrodata::DataExtractor.extract_topic_data(topic) og_builder = DiscourseRichMicrodata::Builders::OpenGraphBuilder.new(data, { language_og: 'en_US' }) puts og_builder.build ``` -------------------------------- ### Extract Meta Tags with cURL Source: https://context7.com/kaktaknet/discourse-rich-json-ld-microdata/llms.txt Fetch a page using cURL and filter for meta tags using grep. This command displays the first 30 meta tags found on the page. ```bash # View all meta tags in page head curl -s https://your-forum.com/t/topic-slug/123 | \ grep -E ' { head: "...", body: "" } # Insert into HTML
result[:head].html_safe # Output includes: # - LLM indexing meta tags (llms-txt, llms-full-txt, llms-sitemaps-txt) # - Open Graph tags (og:locale, og:image:width/height, article:modified_time, article:tag) # - Twitter Card tags (twitter:card, twitter:label1/data1, twitter:label2/data2) # - JSON-LD QAPage/DiscussionForumPosting schema with Question, Answers, Comments # - BreadcrumbList schema # - WebSite schema with SearchAction ``` -------------------------------- ### Generate User Profile Metadata with MetaGeneratorService Source: https://context7.com/kaktaknet/discourse-rich-json-ld-microdata/llms.txt Generates a ProfilePage schema with a Person entity for user profile pages. This includes user statistics, avatar, bio, and activity metrics if enabled. Ensure correct language options are provided. ```ruby # Generate metadata for a user profile user = User.find_by(username: "john_doe") language_options = { language: "ru-RU", language_og: "ru_RU", language_code: "ru", i18n_locale: :ru } result = MetaGeneratorService.generate_for_user(user, language_options) # Generated ProfilePage JSON-LD: # { # "@context": "https://schema.org", # "@type": "ProfilePage", # "@id": "https://forum.example.com/u/john_doe", # "name": "Профиль пользователя John Doe", # "mainEntity": { # "@type": "Person", # "name": "John Doe", # "identifier": "john_doe", # "image": { "@type": "ImageObject", "url": "https://forum.example.com/user_avatar/...", "width": 240, "height": 240 }, # "interactionStatistic": [ # { "@type": "InteractionCounter", "interactionType": "WriteAction", "userInteractionCount": 45, "description": "Создано тем" }, # { "@type": "InteractionCounter", "interactionType": "CommentAction", "userInteractionCount": 312, "description": "Написано ответов" }, # { "@type": "InteractionCounter", "interactionType": "LikeAction", "userInteractionCount": 892, "description": "Получено лайков" } # ] # } # } ``` -------------------------------- ### Enable Debug Mode and Extract Topic Data Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/README.md Enable debug mode in SiteSettings and extract specific topic data for debugging validation errors. Requires Ruby and access to the Discourse environment. ```ruby SiteSetting.rich_microdata_debug_mode = true topic = Topic.find(123) data = DiscourseRichMicrodata::DataExtractor.extract_topic_data(topic) puts JSON.pretty_generate(data) ``` -------------------------------- ### Manual Testing: Language Detection Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Tests the language detection functionality by mocking a user's locale and verifying that the correct translations are used in the generated meta tags. ```ruby # Mock user locale user.update(locale: 'ru') controller = mock_controller(current_user: user) result = MetaGeneratorService.generate_for_topic(topic, nil, controller) # Check if Russian translations are used ``` -------------------------------- ### Format Date for Schema.org Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Uses the `iso8601_date` helper to format dates correctly for schema.org markup. Avoid using `to_s` directly as it may not be in the required ISO 8601 format. ```ruby # Use iso8601_date helper "dateCreated" => iso8601_date(data[:created_at]) # NOT: data[:created_at].to_s ``` -------------------------------- ### Test Language Detection with User Locale Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Tests the language detection mechanism by setting a user's locale and generating meta data. Verifies that translations are used. ```ruby # Mock user locale user = User.find_by(username: 'ivan') user.update(locale: 'ru') controller.instance_variable_set(:@current_user, user) # Generate with user's language result = MetaGeneratorService.generate_for_topic(topic, nil, controller) # Check if Russian translations are used puts result[:body] # Should contain "Главная" instead of "Home" ``` -------------------------------- ### Check RichMicrodata Logs Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Command to tail the development log file and filter for lines containing 'RichMicrodata', useful for debugging. ```bash tail -f log/development.log | grep RichMicrodata ``` -------------------------------- ### Testing Translations in Rails Console Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Demonstrates how to test translations directly within the Rails console by setting the locale and using the I18n.t method with and without interpolation. ```ruby # Rails console I18n.locale = :fr I18n.t('discourse_rich_microdata.breadcrumb.home') # => "Accueil" I18n.t('discourse_rich_microdata.open_graph.category_description', category_name: 'Tech') # => "Discussions dans Tech" ``` -------------------------------- ### Run RSpec Tests for Plugin Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Executes the RSpec tests for the Discourse Rich JSON-LD Microdata plugin. ```bash bundle exec rspec plugins/discourse-rich-json-ld-microdata/spec ``` -------------------------------- ### Generate Meta Markup for User Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Generates meta markup for a user. Requires a User object as input. ```ruby user = User.find_by(username: 'john-dev') result = MetaGeneratorService.generate_for_user(user) ``` -------------------------------- ### Configure Twitter Large Image Cards Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Enables large image cards for Twitter by setting the Twitter site handle in admin settings. Verifies the correct card type is generated. ```ruby builder = DiscourseRichMicrodata::Builders::TwitterCardBuilder.new(data, {}) result = builder.build result["twitter:card"] # => "summary_large_image" ``` -------------------------------- ### Check Image Accessibility with Curl Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Verifies if an image URL is accessible by making an HTTP HEAD request. A '200 OK' response indicates the image is available. ```bash curl -I https://forum.com/uploads/image.jpg # => Should return 200 OK ``` -------------------------------- ### Monitor Cache Hit Rate Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Ruby code to add to `MetaGeneratorService` to monitor and calculate the cache hit rate. Includes methods to increment hits and misses, and a method to retrieve the rate. ```ruby # Add to lib/discourse_rich_microdata/meta_generator_service.rb def self.cache_hit_rate hits = Rails.cache.read('rich_microdata:cache_hits') || 0 misses = Rails.cache.read('rich_microdata:cache_misses') || 0 total = hits + misses return 0 if total == 0 (hits.to_f / total * 100).round(2) end def self.increment_cache_hit Rails.cache.increment('rich_microdata:cache_hits', 1, initial: 0) end def self.increment_cache_miss Rails.cache.increment('rich_microdata:cache_misses', 1, initial: 0) end ``` -------------------------------- ### Generate Category Metadata with MetaGeneratorService Source: https://context7.com/kaktaknet/discourse-rich-json-ld-microdata/llms.txt Generates CollectionPage schema and associated meta tags for category listing pages. This includes subcategory information and topic/post counts. Ensure language options are correctly extracted. ```ruby # Generate metadata for a Discourse category category = Category.find(5) language_options = DiscourseRichMicrodata::LanguageHelper.extract_language_options(controller) result = MetaGeneratorService.generate_for_category(category, language_options) # => { head: "...", body: "" } # The generated JSON-LD includes: # { # "@context": "https://schema.org", # "@type": "CollectionPage", # "@id": "https://forum.example.com/c/support/5", # "name": "Support", # "description": "Get help with technical issues", # "hasPart": [ # { "@type": "CollectionPage", "name": "FAQ", "numberOfItems": 42 }, # { "@type": "CollectionPage", "name": "Tutorials", "numberOfItems": 28 } # ], # "interactionStatistic": [ # { "@type": "InteractionCounter", "interactionType": "WriteAction", "userInteractionCount": 1500 } # ] # } ``` -------------------------------- ### Compact Hashes Before Returning Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Ensure that hashes returned from methods do not contain nil values. Use a utility function like `compact_hash` to clean up the hash before returning it. ```ruby compact_hash(hash) ``` -------------------------------- ### Generate Meta Markup for Category Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Generates meta markup for a category. Requires a Category object as input. ```ruby category = Category.find(5) result = MetaGeneratorService.generate_for_category(category) ``` -------------------------------- ### Reduce Memory Usage Settings Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Configuration settings to reduce memory usage on large forums, including limiting answer extraction, disabling user stats, and using a shorter cache TTL. ```yaml rich_microdata_max_answers: 5 rich_microdata_max_comments: 3 ``` ```yaml rich_microdata_include_user_stats: false ``` ```yaml rich_microdata_cache_ttl: 1800 # 30 minutes ``` -------------------------------- ### Troubleshoot Markup Not Appearing Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/README.md If markup is not appearing, first check if the `rich_microdata_enabled` site setting is `true` in the Rails console. If it is enabled, try clearing the cache using `MetaGeneratorService.clear_all_cache`. ```ruby # Check if enabled SiteSetting.rich_microdata_enabled # => true # Clear cache MetaGeneratorService.clear_all_cache ``` -------------------------------- ### Generate Monthly Microdata Report Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Generates a monthly report detailing cache statistics for microdata generation, including counts of cached items, hit rate, and total cache size. ```ruby # Monthly report puts "Microdata Generation Report" puts "===========================" puts "Topics cached: #{MetaGeneratorService.cache_stats[:topics]}" puts "Categories cached: #{MetaGeneratorService.cache_stats[:categories]}" puts "Users cached: #{MetaGeneratorService.cache_stats[:users]}" puts "Cache hit rate: #{MetaGeneratorService.cache_hit_rate}%" puts "Total cache size: #{MetaGeneratorService.cache_stats[:total_size]}" ``` -------------------------------- ### Adjust Answer and Comment Limits Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Configure the maximum number of answers and comments to include in QAPage schema. Adjusting these limits impacts JSON-LD size and recommended values are provided. ```yaml rich_microdata_max_answers: 20 # Default: 10 rich_microdata_max_comments: 10 # Default: 5 ``` -------------------------------- ### View Full HTML Head Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/README.md Retrieve the complete HTML content of the `` section for a given URL using `curl`. This is useful for a comprehensive review of all meta tags and linked resources. ```bash # View full head curl https://your-forum.com/t/topic-slug/123 | grep -A 50 "" ``` -------------------------------- ### Clone Discourse Rich JSON-LD Microdata Plugin Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Clones the plugin repository into the Discourse plugins directory for local development. ```bash cd discourse git clone https://github.com/kaktaknet/discourse-rich-json-ld-microdata.git plugins/discourse-rich-json-ld-microdata ``` -------------------------------- ### Define Question Entity for Schema.org Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/USAGE.md Ensures all required fields for a 'Question' schema type are present. This is crucial for accurate representation in search results. ```ruby # Edit lib/discourse_rich_microdata/builders/qa_page_builder.rb # Ensure all required fields are present def question_entity { "@type" => "Question", "name" => data[:title], # Required "text" => data[:excerpt], # Required "answerCount" => data[:posts_count] - 1 # Required } end ``` -------------------------------- ### Update Plugin Version in plugin.rb Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Shows how to update the plugin's version number within the `plugin.rb` file, following Semantic Versioning guidelines. ```ruby # version: 2.1.0 ``` -------------------------------- ### Create New Feature Branch Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Creates a new Git branch for developing a feature, following a standard naming convention. ```bash git checkout -b feature/your-feature-name ``` -------------------------------- ### Avoid Database Queries in Builders Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md When building data structures, avoid direct database queries within builder methods. Instead, pass necessary data through a hash to maintain performance and separation of concerns. ```ruby User.find(author_id) ``` -------------------------------- ### Check Ruby Syntax Errors with RuboCop Source: https://github.com/kaktaknet/discourse-rich-json-ld-microdata/blob/main/CONTRIBUTING.md Uses RuboCop to check for Ruby syntax errors and style violations within the plugin directory. ```bash rubocop plugins/discourse-rich-json-ld-microdata ```