| title | URL Replacement System | ||||||
|---|---|---|---|---|---|---|---|
| description | Documentation for the URL replacement system used to maintain consistent links across the Edge AI project documentation | ||||||
| author | Edge AI Team | ||||||
| ms.date | 2025-06-06 | ||||||
| ms.topic | concept | ||||||
| estimated_reading_time | 8 | ||||||
| keywords |
|
The Edge AI project uses a context-aware, variable-based URL replacement system to ensure documentation links work correctly across different publishing contexts (local development, GitHub Pages, Azure DevOps Wiki).
Instead of hardcoded URLs, our documentation uses variable tokens that are replaced at build-time or runtime:
<!-- Instead of hardcoded URLs -->
[Clone the repository](https://github.com/microsoft/edge-ai.git)
<!-- We use tokens -->
[Clone the repository]({{CLONE_URL}})| Token | Description | Example |
|---|---|---|
{{REPO_URL}} |
Repository home page | https://github.com/microsoft/edge-ai |
{{CLONE_URL}} |
Git clone URL | https://github.com/microsoft/edge-ai.git |
{{ISSUES_URL}} |
Issues/bug tracker | https://github.com/microsoft/edge-ai/issues |
{{NEW_ISSUE_URL}} |
Create new issue | https://github.com/microsoft/edge-ai/issues/new |
{{DOCS_BASE_URL}} |
Documentation base | https://microsoft.github.io/edge-ai |
The system supports three publishing contexts, each with different URL patterns:
- Repo URL:
https://github.com/microsoft/edge-ai - Clone URL:
https://github.com/microsoft/edge-ai.git - Issues URL:
https://github.com/microsoft/edge-ai/issues - Docs Base:
http://localhost:3000(when serving locally)
- Repo URL:
https://github.com/microsoft/edge-ai - Clone URL:
https://github.com/microsoft/edge-ai.git - Issues URL:
https://github.com/microsoft/edge-ai/issues - Docs Base:
https://microsoft.github.io/edge-ai
- Repo URL:
https://dev.azure.com/msazure/One/_git/edge-ai - Clone URL:
https://dev.azure.com/msazure/One/_git/edge-ai - Issues URL:
https://dev.azure.com/msazure/One/_workitems/edit/new - Docs Base:
https://dev.azure.com/msazure/One/_wiki/wikis/edge-ai.wiki
When writing documentation, always use tokens instead of hardcoded URLs:
<!-- ✅ Good -->
For more information, visit our [repository]({{REPO_URL}}).
To report a bug, [create an issue]({{NEW_ISSUE_URL}}).
<!-- ❌ Avoid -->
For more information, visit our [repository](https://github.com/microsoft/edge-ai).# Serve docs with runtime URL replacement
npm run docs
# Or serve for a specific context
npm run docs:github
npm run docs:azdo# Replace URLs for GitHub context
npm run url:github
# Replace URLs for Azure DevOps context
npm run url:azdo
# Restore original tokens
npm run url:restore
# Check current URL status
npm run url:statusFor build pipelines that generate static files:
# In your build script
./scripts/replace-urls.sh github # or 'azdo'For serving with dynamic replacement:
# Use npm scripts for local development
npm run docs # Start server with browser opening
npm run docs:no-open # Start server without opening browserThe system uses a centralized configuration file that defines URL mappings for each context:
{
"contexts": {
"local": {
"REPO_URL": "https://github.com/microsoft/edge-ai",
"CLONE_URL": "https://github.com/microsoft/edge-ai.git",
"ISSUES_URL": "https://github.com/microsoft/edge-ai/issues",
"NEW_ISSUE_URL": "https://github.com/microsoft/edge-ai/issues/new",
"DOCS_BASE_URL": "http://localhost:3000"
},
"github": {
"REPO_URL": "https://github.com/microsoft/edge-ai",
"CLONE_URL": "https://github.com/microsoft/edge-ai.git",
"ISSUES_URL": "https://github.com/microsoft/edge-ai/issues",
"NEW_ISSUE_URL": "https://github.com/microsoft/edge-ai/issues/new",
"DOCS_BASE_URL": "https://microsoft.github.io/edge-ai"
},
"azdo": {
"REPO_URL": "https://dev.azure.com/msazure/One/_git/edge-ai",
"CLONE_URL": "https://dev.azure.com/msazure/One/_git/edge-ai",
"ISSUES_URL": "https://dev.azure.com/msazure/One/_workitems/edit/new",
"NEW_ISSUE_URL": "https://dev.azure.com/msazure/One/_workitems/edit/new",
"DOCS_BASE_URL": "https://dev.azure.com/msazure/One/_wiki/wikis/edge-ai.wiki"
}
}
}Create a .env file (based on .env.example) to override URLs for your local environment:
# Local environment overrides
REPO_URL=https://github.com/your-fork/edge-ai
CLONE_URL=https://github.com/your-fork/edge-ai.gitUniversal URL replacement script with multiple operation modes:
# Context-based replacement
./scripts/replace-urls.sh <context> # github, azdo, local
# Direct replacement
./scripts/replace-urls.sh --replace "{{TOKEN}}" "value"
# Restoration
./scripts/replace-urls.sh --restore
# Status check
./scripts/replace-urls.sh --statusHelper script for common local development tasks:
# Setup local environment
./scripts/local-url-replace.sh --setup
# Replace with environment variables
./scripts/local-url-replace.sh --replace
# Restore original tokens
./scripts/local-url-replace.sh --restore
# Show current status
./scripts/local-url-replace.sh --statusEnhanced documentation server with runtime URL replacement:
# Start local development server (port 8080, with browser opening)
npm run docs
# Start server without opening browser
npm run docs:no-open
# Generate URL configuration for development
npm run docs:build-dev
# Generate URL configuration for production (GitHub Pages)
npm run docs:buildThe runtime replacement system works by:
- Generating a JavaScript config file (
docsify-url-config.js) based on the selected context - Loading a Docsify plugin that performs client-side URL replacement
- Replacing tokens in the rendered HTML before display
The static replacement system:
- Reads the configuration from
scripts/url-config.json - Processes all markdown files in the documentation
- Replaces tokens with context-specific URLs
- Maintains backup functionality for restoration
The system processes files matching these patterns:
README.md(root)docs/**/*.mdblueprints/**/README.md- Any file containing URL tokens
- Original files are backed up before replacement
- Backups are stored with
.backupextension - Restoration removes replaced files and restores backups
- Git status is checked to prevent data loss
- URLs not replacing: Check that tokens are properly formatted with double curly braces
- Context not found: Verify the URL configuration is generated correctly with
npm run docs:build-dev - Permission errors: Make sure scripts have execute permissions (
chmod +x) - Port conflicts: Default port is 8080; docsify will automatically find available port if needed
# Check what would be replaced
./scripts/replace-urls.sh --status
# Verify configuration
cat scripts/url-config.json | jq '.contexts'
# Test runtime replacement
npm run docs -- --verboseIf something goes wrong:
# Restore from backups
./scripts/replace-urls.sh --restore
# Or reset from git
git checkout -- docs/ README.mdWhen adding new URL tokens:
- Add the token to all contexts in
scripts/url-config.json - Update this documentation
- Test with all contexts (
local,github,azdo) - Verify both static and runtime replacement work
When modifying scripts:
- Ensure backward compatibility
- Update help text and documentation
- Test error handling and edge cases
- Maintain the backup/restore functionality
🤖 Crafted with precision by ✨Copilot following brilliant human instruction, then carefully refined by our team of discerning human reviewers.