### Start the NeoDB Cluster Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Start all services for the NeoDB cluster using the development profile. This command brings up the web servers and other necessary components. ```bash docker compose --profile dev up -d ``` -------------------------------- ### Install uv, Packages, and Pre-commit Hooks Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Install the uv package manager, synchronize project dependencies, activate the virtual environment, and set up pre-commit hooks for code quality. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh uv sync . .venv/bin/activate pre-commit install ``` -------------------------------- ### Download Docker Images and Start Services Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Pull the necessary Docker images and start the PostgreSQL, Redis, and Typesense services in detached mode. This prepares the database and cache infrastructure. ```bash docker compose --profile dev pull docker compose up -d ``` -------------------------------- ### Preview Documentation with MkDocs Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Serve the MkDocs documentation locally to preview changes before deployment. Requires MkDocs to be installed. ```bash python -m mkdocs serve ``` -------------------------------- ### Test Docker Installation Source: https://github.com/neodb-social/neodb/blob/main/docs/install.md Ensure Docker is installed correctly and can run containers without sudo privileges. ```bash docker run --rm hello-world ``` -------------------------------- ### Email Sender Configuration Examples Source: https://github.com/neodb-social/neodb/blob/main/docs/configuration.md Examples of email sender configurations for the NEODB_EMAIL_URL setting. Supports standard SMTP, TLS, SSL, and Anymail backends. ```env smtp://:@: ``` ```env smtp+tls://:@: ``` ```env smtp+ssl://:@: ``` ```env anymail://? ``` -------------------------------- ### Initialize and Configure Garage Source: https://github.com/neodb-social/neodb/blob/main/docs/configuration.md Commands to initialize Garage, assign node layout, and create buckets and keys. These commands are executed after the service starts. ```bash # Assign node layout docker compose exec garage /garage -c /etc/garage.toml status docker compose exec garage /garage -c /etc/garage.toml layout assign -z dc1 -c 1G docker compose exec garage /garage -c /etc/garage.toml layout apply --version 1 # Create bucket and key docker compose exec garage /garage -c /etc/garage.toml bucket create media docker compose exec garage /garage -c /etc/garage.toml key create neodb-app-key docker compose exec garage /garage -c /etc/garage.toml bucket allow --read --write --owner media --key neodb-app-key docker compose exec garage /garage -c /etc/garage.toml bucket website --allow media ``` -------------------------------- ### NodeInfo JSON Example Source: https://github.com/neodb-social/neodb/blob/main/docs/internals/federation.md Example of NodeInfo JSON response for a NeoDB instance, indicating supported protocols. ```json { "version": "2.0", "software": { "name": "neodb", "version": "0.10.4.13", "repository": "https://github.com/neodb-social/neodb", "homepage": "https://neodb.net/" }, "protocols": ["activitypub", "neodb"], } ``` -------------------------------- ### Clone NeoDB and Initialize Submodules Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Clone the NeoDB repository and ensure all submodules are initialized. This is a crucial first step before installing dependencies. ```bash git clone https://github.com/neodb-social/neodb.git cd neodb git submodule update --init ``` -------------------------------- ### Initialize Database Schema and Collect Static Files Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Run Django's `collectstatic` command to gather static files and then execute `neodb-init` to set up the database schema. These commands are essential after initial setup or code updates. ```bash docker compose --profile dev run --rm dev-shell takahe-manage collectstatic --noinput docker compose --profile dev run --rm dev-shell neodb-init ``` -------------------------------- ### Create SeaweedFS Bucket Source: https://github.com/neodb-social/neodb/blob/main/docs/configuration.md Use the AWS CLI to create the 'media' bucket in SeaweedFS after the service has started. Ensure the endpoint URL matches your SeaweedFS configuration. ```bash aws --endpoint-url http://localhost:8333 s3 mb s3://media ``` -------------------------------- ### Add New Site Command Example Source: https://github.com/neodb-social/neodb/blob/main/docs/internals/catalog.md Command to run for debugging or saving response files to /tmp. Detailed code for the 'cat' command is located in catalog/management/commands/cat.py. ```bash neodb-manage cat ``` -------------------------------- ### Passkey Registration Logic Source: https://github.com/neodb-social/neodb/blob/main/users/templates/users/welcome.html Initializes passkey registration if the browser supports it. It shows the passkey prompt, hides the accept button, and sets up an event listener for the passkey setup button. This code handles the entire passkey creation flow, including calling the registration options and verification URLs, and updating the UI based on success or failure. ```javascript (function() { if (!window.Passkey || !Passkey.isSupported()) return; document.getElementById('passkey-prompt').style.display = ''; document.getElementById('accept-btn').style.display = 'none'; var btn = document.getElementById('passkey-setup-btn'); var status = document.getElementById('passkey-setup-status'); btn.addEventListener('click', function() { btn.setAttribute('aria-busy', 'true'); status.textContent = ''; Passkey.register( '{% url "users:passkey_register_options" %}', '{% url "users:passkey_register_verify" %}', function() { btn.removeAttribute('aria-busy'); btn.disabled = true; btn.textContent = '{% trans "Passkey created" %}'; }, function(err) { btn.removeAttribute('aria-busy'); if (err) status.textContent = err; } ); }); })(); ``` -------------------------------- ### Initialize Shikwasa Podcast Player Source: https://github.com/neodb-social/neodb/blob/main/catalog/templates/embed_podcast.html Initializes the Shikwasa player with episode details and autoplay enabled. Use this when embedding a podcast player that should start playing immediately. ```javascript $(function(){ if (focus_item) { var position = 1 * "{{request.GET.position|escapejs}}"; window.current_item_uuid = "{{focus_item.uuid}}"; window.player = new Shikwasa.Player({ container: () => document.querySelector('body'), preload: 'metadata', autoplay: true, theme: 'dark', themeColor: '#837FFF', audio: { title: "{{ focus_item.display_title | escapejs }}", cover: "{{ focus_item.cover_url | default:item.cover.url | escapejs }}", src: "{{ focus_item.media_url | escapejs }}", album: "{{ item.display_title|escapejs }}", artist: "{{ item.host_names|join:' / '|escapejs }}" } }); if (position) window.player._initSeek = position; } }); ``` -------------------------------- ### Configure Development Environment Variables Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Set up the necessary environment variables in a `.env` file for local development. Ensure these variables are present before starting the Docker services. ```dotenv NEODB_SITE_NAME="My Test" NEODB_SITE_DOMAIN=mydomain.dev NEODB_SECRET_KEY=_random_string__50_characters_of_length__no_whitespaces_ NEODB_IMAGE=neodb/neodb:edge NEODB_DEBUG=True ``` -------------------------------- ### Accessing NeoDB APIs Source: https://github.com/neodb-social/neodb/blob/main/common/templates/console.html Information on how to authorize API requests and examples of using access tokens. ```APIDOC ## Accessing NeoDB APIs ### Description Invoke APIs with your account by authorizing with an access token. This is required for APIs like `/api/me`. ### Authorization Click the `Authorize` button and input your token. Alternatively, use it in the command line. ### Command Line Example ```bash curl -H "Authorization: Bearer YOUR_TOKEN" {{ site_url }}/api/me ``` ### Further Details Please check [NeoDB documentation](https://neodb.net/api/) for details on how to authorize. ``` -------------------------------- ### Authorize user Source: https://github.com/neodb-social/neodb/blob/main/docs/api.md Guide your user to open the authorization URL to grant your application access. ```APIDOC ## Guide your user to open this URL ``` https://neodb.social/oauth/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https://example.org/callback&scope=read+write ``` ### Once authorizated by user, it will redirect to `https://example.org/callback` with a `code` parameter: ``` https://example.org/callback?code=AUTH_CODE ``` ``` -------------------------------- ### Markdown Formatting Examples Source: https://github.com/neodb-social/neodb/blob/main/journal/templates/markdown_editor.html Demonstrates various Markdown syntax elements including links, emphasis, highlights, quotes, lists, code blocks, tables, and images. Use these for reference when writing Markdown. ```markdown {% load i18n %} **{% trans "Markdown format references" %}** {% blocktrans %} ## Subtitle Paragraphs need to be separated by a blank line [Link](https://zh.wikipedia.org/wiki/Markdown) **Bold** *Italic* ~~Strikethrough~~ ==Highlight== ^Super^script ~Sub~script > Quote >> Multi-level quote Inline >! spoiler warning !< >! Multi-line >! Spoiler --- - Bullet - Points ``` code ``` Table Header | Second Header ------------- | ------------- Content Cell | Content Cell Content Cell | Content Cell Paste or upload an image ![Image](https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg) {% endblocktrans %} ``` -------------------------------- ### Verify Docker Compose Version Source: https://github.com/neodb-social/neodb/blob/main/docs/install.md Check if Docker Compose is installed and meets the minimum version requirement (2.x or higher). ```bash docker compose version ``` -------------------------------- ### Passkey Nudge Logic Source: https://github.com/neodb-social/neodb/blob/main/common/templates/_header.html Manages the display and dismissal of a passkey setup prompt for authenticated users. Ensures the prompt is shown only once per session. ```javascript (function() { if (!window.PublicKeyCredential || sessionStorage.getItem('passkey_nudge_dismissed')) return; var el = document.getElementById('passkey-nudge'); if (el) el.style.display = ''; var dismiss = document.getElementById('passkey-nudge-dismiss'); if (dismiss) dismiss.addEventListener('click', function(e) { e.preventDefault(); sessionStorage.setItem('passkey_nudge_dismissed', '1'); el.style.display = 'none'; }); })(); ``` -------------------------------- ### Get Search Index Information Source: https://github.com/neodb-social/neodb/blob/main/docs/usage/catalog.md Displays information about the current state and configuration of the search index. ```bash neodb-manage catalog idx-info ``` -------------------------------- ### Authorize User URL Source: https://github.com/neodb-social/neodb/blob/main/docs/api.md Construct this URL to guide your user through the OAuth authorization process. Replace CLIENT_ID and redirect_uri with your application's specific values. ```url https://neodb.social/oauth/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https://example.org/callback&scope=read+write ``` -------------------------------- ### Initialize Calendar View with Data and Options Source: https://github.com/neodb-social/neodb/blob/main/journal/templates/calendar_data.html Initializes the calendar view using jQuery and a JSON data source. Configure start day, tooltip behavior, and custom month/day names. Define specific colors for event types like 'book', 'movie', etc., falling back to a default form element background color. ```javascript {% load i18n %} {{ calendar_data|json_script:"calendar_data" }} $(".calendar_view").calendar_yearview_blocks({ data: $("#calendar_data").text(), start_monday: false, always_show_tooltip: false, month_names: [ '{% trans "JAN" %}', '{% trans "FEB" %}', '{% trans "MAR" %}', '{% trans "APR" %}', '{% trans "MAY" %}', '{% trans "JUN" %}', '{% trans "JUL" %}', '{% trans "AUG" %}', '{% trans "SEP" %}', '{% trans "OCT" %}', '{% trans "NOV" %}', '{% trans "DEC" %}' ], day_names: ['', '', ''], colors: { 'default': getComputedStyle(document.documentElement).getPropertyValue('--pico-form-element-background-color'), 'book': '#B4D2A5', 'movie': '#7CBDFE', 'tv': '#FDDB23', 'music': '#FEA36D', 'game': '#C5A290', 'podcast': '#9D6AB0', 'performance': '#FE7C7C', 'other': '#FED37C' } }); ``` -------------------------------- ### Obtain Access Token Source: https://github.com/neodb-social/neodb/blob/main/docs/api.md Send a POST request with your application credentials and the authorization code to this endpoint to get an access token. This token is used to authenticate API requests. ```bash curl https://neodb.social/oauth/token \ -d "client_id=CLIENT_ID" \ -d "client_secret=CLIENT_SECRET" \ -d "code=AUTH_CODE" \ -d "redirect_uri=https://example.org/callback" \ -d "grant_type=authorization_code" ``` -------------------------------- ### Get Current Language Source: https://github.com/neodb-social/neodb/blob/main/journal/templates/wrapped.html Retrieves the current language code for internationalization purposes. ```django {% get_current_language as LANGUAGE_CODE %} ``` -------------------------------- ### Create an application Source: https://github.com/neodb-social/neodb/blob/main/docs/api.md Register a new application to obtain client credentials for API access. ```APIDOC ## Create an application You must have at least one URL included in the Redirect URIs field, e.g. `https://example.org/callback`, or use `urn:ietf:wg:oauth:2.0:oob` if you don't have a callback URL. ``` curl https://neodb.social/api/v1/apps \ -d client_name=MyApp \ -d redirect_uris=https://example.org/callback \ -d website=https://my.site ``` and save of the `client_id` and `client_secret` returned in the response: ``` { "client_id": "CLIENT_ID", "client_secret": "CLIENT_SECRET", "name": "MyApp", "redirect_uri": "https://example.org/callback", "vapid_key": "PUSH_KEY", "website": "https://my.site" } ``` ``` -------------------------------- ### Get current user information Source: https://github.com/neodb-social/neodb/blob/main/docs/api.md Retrieve information about the currently authenticated user. ```APIDOC ### Use the access token to access protected endpoints like `/api/me` ``` curl -H "Authorization: Bearer ACCESS_TOKEN" -X GET https://neodb.social/api/me ``` and response will be returned accordingly: ``` {"url": "https://neodb.social/users/xxx/", "external_acct": "xxx@yyy.zzz", "display_name": "XYZ", "avatar": "https://yyy.zzz/xxx.gif"} ``` ``` -------------------------------- ### Create Superuser Account Source: https://github.com/neodb-social/neodb/blob/main/docs/accounts.md Execute this command to create a superuser account. Alternatively, configure the NEODB_ADMIN_HANDLES environment variable to automatically promote users with matching handles upon registration. ```bash docker compose --profile production run --rm shell neodb-manage createsuperuser ``` ```dotenv NEODB_ADMIN_HANDLES=mastodon:user@mastodon.social,email:admin@example.com ``` -------------------------------- ### List All Accounts Source: https://github.com/neodb-social/neodb/blob/main/docs/accounts.md Use this command to view all accounts on your instance. Be aware that this output includes sensitive information such as email addresses and fediverse accounts. ```bash docker compose --profile production run --rm shell neodb-manage user --list ``` -------------------------------- ### Protected Endpoint Response Example Source: https://github.com/neodb-social/neodb/blob/main/docs/api.md A successful request to a protected endpoint will return data related to the authenticated user or resource. ```json {"url": "https://neodb.social/users/xxx/", "external_acct": "xxx@yyy.zzz", "display_name": "XYZ", "avatar": "https://yyy.zzz/xxx.gif"} ``` -------------------------------- ### Toggle Account to Admin Source: https://github.com/neodb-social/neodb/blob/main/docs/accounts.md Promote an existing user account to admin status. Exercise caution, as admins have extensive control over the instance. ```bash docker compose --profile production run --rm shell neodb-manage user --super [USERNAME] ``` -------------------------------- ### Conditional Display of Episode Comments Source: https://github.com/neodb-social/neodb/blob/main/catalog/templates/_item_comments_by_episode.html Conditionally displays episode comments if the 'last' GET parameter is not present. Otherwise, it shows a link to comment. ```html {% if not request.GET.last %} {% trans "this season" %} {% for ep in item.all_episodes %} {{ ep.episode_number }} {% endfor %} [{% if mark.comment_text %} {% else %} {% endif %} {% trans "comment this episode" ](#) $(function(){ window.cil.forEach(function(uuid){ $('#ci_'+uuid).addClass('marked'); }) }); {% endif %} ``` -------------------------------- ### Initialize Database Schema using neodb-init Source: https://github.com/neodb-social/neodb/blob/main/docs/development.md Update the database schema using the `neodb-init` command. This is the recommended way to migrate the database after code updates, rather than using `python3 manage.py migrate` directly. ```bash neodb-shell neodb-init ``` -------------------------------- ### Passkey Login Initialization and Event Handling Source: https://github.com/neodb-social/neodb/blob/main/users/templates/users/login.html Initializes the passkey login button, checks for passkey support, and attaches a click event listener to initiate the passkey login process. It handles success and error callbacks. ```javascript (function() { if (!window.Passkey || !Passkey.isSupported()) return; var btn = document.getElementById('passkey-login-btn'); if (!btn) return; btn.addEventListener('click', function() { localStorage.login_method = 'passkey'; btn.setAttribute('aria-busy', 'true'); var errEl = document.getElementById('passkey-error'); errEl.style.display = 'none'; Passkey.login( '{% url "users:passkey_login_options" %}', '{% url "users:passkey_login_verify" %}', function(result) { location.href = result.redirect || '/'; }, function(err) { btn.removeAttribute('aria-busy'); if (err) { errEl.textContent = err; errEl.style.display = ''; } } ); }); })(); ``` -------------------------------- ### Testing Storage Configuration Source: https://github.com/neodb-social/neodb/blob/main/docs/configuration.md Run this command to test your configured storage backend, ensuring files can be uploaded and accessed. ```bash neodb-manage catalog storage-test ``` -------------------------------- ### Initialize Search Index Source: https://github.com/neodb-social/neodb/blob/main/docs/usage/catalog.md Checks if the search index exists and creates it if it is missing. ```bash neodb-manage catalog idx-init ``` -------------------------------- ### Initialize and Save Device Settings (JavaScript) Source: https://github.com/neodb-social/neodb/blob/main/users/templates/users/_pref_device.html This script initializes UI elements based on local storage and cookie values for theme, custom styles, focus mode, demetrication, and items per page. It also includes a function to save these settings. ```javascript var _c=$('html').attr('data-theme')||""; if (_c=="light") $('input[id=theme_light]').prop('checked', true); if (_c=="dark") $('input[id=theme_dark]').prop('checked', true); if (! _c) $('input[id=theme_auto]').prop('checked', true); $("#user_style").val(localStorage.getItem("user_style")||""); $("#solo_mode").prop("checked", localStorage.getItem("solo_mode")=="1"); $("#demetrication").prop("checked", localStorage.getItem("demetrication")=="1"); var _p=Cookies.get('per_page') || 20; $('#'+_p+'_per_page').prop('checked', true); function save_local() { var _c=$('input[name=theme_color]:checked').val(); $('html').attr('data-theme', _c||""); localStorage.setItem("theme_color", _c); localStorage.setItem("user_style", $("#user_style").val()); localStorage.setItem("solo_mode", $("#solo_mode").prop("checked")?"1":"0"); localStorage.setItem("demetrication", $("#demetrication").prop("checked")?"1":"0"); Cookies.set('per_page', $('input[name=per_page]:checked').val(), {expires: 120, sameSite: 'Lax'}); alert("{% trans 'Settings for current device saved' %}"); } ``` -------------------------------- ### Create NeoDB Application Source: https://github.com/neodb-social/neodb/blob/main/docs/api.md Use this cURL command to create a new application on NeoDB. Ensure you provide a client name, redirect URIs, and optionally a website. ```bash curl https://neodb.social/api/v1/apps \ -d client_name=MyApp \ -d redirect_uris=https://example.org/callback \ -d website=https://my.site ``` -------------------------------- ### Local Storage URL History Management Source: https://github.com/neodb-social/neodb/blob/main/catalog/templates/scraper_debug.html Manages a history of scraped URLs using local storage. Includes functions to get, save, clear, and update the UI for URL history, with a maximum limit. ```javascript let currentMode = 'site'; const HISTORY_KEY = 'scraper_debug_url_history'; const MAX_HISTORY = 20; function getHistory() { try { return JSON.parse(localStorage.getItem(HISTORY_KEY)) || []; } catch { return []; } } function saveToHistory(url) { if (!url) return; let history = getHistory(); history = history.filter(u => u !== url); history.unshift(url); if (history.length > MAX_HISTORY) history = history.slice(0, MAX_HISTORY); localStorage.setItem(HISTORY_KEY, JSON.stringify(history)); updateHistoryUI(); } function clearHistory() { localStorage.removeItem(HISTORY_KEY); updateHistoryUI(); } function updateHistoryUI() { const history = getHistory(); const datalist = document.getElementById('url-history'); const actionsEl = document.getElementById('history-actions'); datalist.innerHTML = history.map(url => `