Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scripts/dev.sh text eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ logs/
temp/*
!temp/keep.txt
.idea
.dev/
# *.py
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ Directories named `archive` under `barcode-reader/{mobile,server,web}/` hold his

If you find yourself wanting to *add* content to an archive directory, it almost certainly belongs in the live directory instead.

## Testing the local site

The Jekyll layout comes from `Docs-Template-Repo`, not this repository. Install Git and Ruby/Bundler plus `rsync` (Bash) or `robocopy` (PowerShell). From the repo root, run `./scripts/dev.sh` or `./scripts/dev.ps1` to prepare `.dev/DocHome` and serve at `http://localhost:5555/faq/`. The scripts exclude archived FAQ directories and local worktrees from that merged workspace.

For preparation without a server, use `./scripts/dev.sh --no-serve` or `./scripts/dev.ps1 -NoServe`; rerun the script without that flag to start the server. Use `--no-template-update` / `-NoTemplateUpdate` to reuse the cloned template. Rerun after editing FAQ source because the merged workspace is a copy, then check the changed page in the local site. `.dev/` is generated and Git-ignored; do not edit it as source.

## Before finishing

Run the link checker from the repo root and fix anything it flags in files you touched:
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ See [`AGENTS.md`](AGENTS.md) for the FAQ article structure, frontmatter, linking

The site is built with Jekyll using a shared theme/layout maintained in [dynamsoft-docs/Docs-Template-Repo](https://github.com/dynamsoft-docs/Docs-Template-Repo), which this repo doesn't include locally. Pushes to `main` and `preview` trigger the CI workflows in `.github/workflows/main.yml`, which build and sync to production and the preview/testing environment respectively.

For a local preview, install Git, Ruby/Bundler, and rsync (Bash) or robocopy (PowerShell), then run from the repository root:

```bash
./scripts/dev.sh
```

Or on Windows:

```powershell
./scripts/dev.ps1
```

The scripts clone the shared template's preview branch into `.dev/`, merge it with this FAQ source, install gems, and serve Jekyll at `http://localhost:5555/faq/`. The generated `.dev/` workspace is ignored by Git and omits archived FAQ content and local worktrees. Use `--no-serve` / `-NoServe` to prepare without serving, then rerun without that flag to serve; `--no-template-update` / `-NoTemplateUpdate` reuses the cloned template. Changes to FAQ files require rerunning the script to refresh the merged workspace.

## Checking links

`check_links.py` crawls the repo's Markdown files and reports broken links. Run it before submitting a change that touches links:

```bash
python check_links.py
```
```
1 change: 1 addition & 0 deletions check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def find_md_files(root_dir):
for root, dirs, files in os.walk(root_dir):
if '.git' in dirs: dirs.remove('.git')
if '_site' in dirs: dirs.remove('_site')
if '.dev' in dirs: dirs.remove('.dev')

for file in files:
if file.endswith('.md'):
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../barcode-reader/web/camera/camera-preview-renders-incorrectly-ios.md
159 changes: 159 additions & 0 deletions scripts/dev.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
[CmdletBinding()]
param(
[string]$TemplateRepoUrl = "https://github.com/dynamsoft-docs/Docs-Template-Repo.git",
[string]$TemplateBranch = "preview",
[int]$Port = 5555,
[string]$BindHost = "localhost",
[switch]$NoTemplateUpdate,
[switch]$NoServe
)

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

function Write-Step {
param([string]$Message)
Write-Host "==> $Message"
}

function Ensure-Command {
param([string]$Name)
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
throw "Required command '$Name' was not found in PATH."
}
}

function Invoke-Native {
param(
[Parameter(Mandatory = $true)]
[string]$FilePath,
[string[]]$Arguments = @()
)

& $FilePath @Arguments
$code = $LASTEXITCODE
if ($code -ne 0) {
$argText = ($Arguments -join " ")
throw "Command failed with exit code ${code}: $FilePath $argText"
}
}

function Invoke-Robocopy {
param(
[string]$Source,
[string]$Destination,
[string[]]$ExtraArgs
)

$baseArgs = @(
$Source,
$Destination,
"/R:2",
"/W:2",
"/NFL",
"/NDL",
"/NJH",
"/NJS",
"/NP"
)
$allArgs = $baseArgs + $ExtraArgs
& robocopy @allArgs | Out-Null
$code = $LASTEXITCODE
if ($code -ge 8) {
throw "robocopy failed with exit code $code. Source: $Source Destination: $Destination"
}
}

Ensure-Command "git"
Ensure-Command "robocopy"
Ensure-Command "bundle"

$repoRoot = Split-Path -Parent $PSScriptRoot
$devRoot = Join-Path $repoRoot ".dev"
$templateRoot = Join-Path $devRoot "Docs-Template-Repo"
$docHome = Join-Path $devRoot "DocHome"
$bundlePath = Join-Path $devRoot "vendor\bundle"
$bundleConfig = Join-Path $devRoot ".bundle"
$bundleUserHome = Join-Path $devRoot ".bundle-user"
$jekyllCache = Join-Path $devRoot ".jekyll-cache"
$siteDir = Join-Path $devRoot "_site"

Write-Step "Preparing local workspace in $devRoot"
New-Item -ItemType Directory -Force -Path $devRoot | Out-Null

if (-not (Test-Path $templateRoot)) {
Write-Step "Cloning template repo ($TemplateBranch)"
Invoke-Native -FilePath "git" -Arguments @("clone", "--depth", "1", "--branch", $TemplateBranch, $TemplateRepoUrl, $templateRoot)
} elseif (-not $NoTemplateUpdate) {
Write-Step "Syncing template repo ($TemplateBranch)"
Invoke-Native -FilePath "git" -Arguments @("-C", $templateRoot, "fetch", "origin", $TemplateBranch, "--depth", "1")
Invoke-Native -FilePath "git" -Arguments @("-C", $templateRoot, "reset", "--hard")
Invoke-Native -FilePath "git" -Arguments @("-C", $templateRoot, "clean", "-fd")
Invoke-Native -FilePath "git" -Arguments @("-C", $templateRoot, "checkout", "-B", $TemplateBranch, "origin/$TemplateBranch")
} else {
Write-Step "Skipping template update"
}

Write-Step "Rebuilding merged site workspace"
if (Test-Path $docHome) {
Remove-Item -LiteralPath $docHome -Recurse -Force
}
New-Item -ItemType Directory -Force -Path $docHome | Out-Null
Invoke-Robocopy -Source $repoRoot -Destination $docHome -ExtraArgs @(
"/MIR",
"/XD", ".git", ".dev", ".claude", ".vs", "node_modules", "_site", ".bundle", ".jekyll-cache", ".sass-cache", "vendor",
(Join-Path $repoRoot "barcode-reader\mobile\archive"),
(Join-Path $repoRoot "barcode-reader\server\archive"),
(Join-Path $repoRoot "barcode-reader\web\archive")
)
Invoke-Robocopy -Source $templateRoot -Destination $docHome -ExtraArgs @(
"/E",
"/XD", ".git", ".github", "_site", "node_modules"
)

Write-Step "Applying local assetsPath replacements"
$search = "assetsPath = '/webres/wwwroot'"
$replace = "assetsPath = 'https://www.dynamsoft.com/webres/wwwroot'"
foreach ($dirName in @("_includes", "_layouts")) {
$dirPath = Join-Path $docHome $dirName
if (-not (Test-Path $dirPath)) {
continue
}

Get-ChildItem -Path $dirPath -Recurse -File | ForEach-Object {
$path = $_.FullName
try {
$content = [System.IO.File]::ReadAllText($path)
} catch {
return
}
if ($content.Contains($search)) {
$updated = $content.Replace($search, $replace)
[System.IO.File]::WriteAllText($path, $updated)
}
}
}

Write-Step "Configuring Bundler and Jekyll local paths"
$env:BUNDLE_PATH = $bundlePath
$env:BUNDLE_APP_CONFIG = $bundleConfig
$env:BUNDLE_USER_HOME = $bundleUserHome
$env:BUNDLE_USER_CACHE = Join-Path $bundleUserHome "cache"
$env:JEKYLL_CACHE_DIR = $jekyllCache
$env:JEKYLL_ENV = "development"
New-Item -ItemType Directory -Force -Path $bundlePath, $bundleConfig, $bundleUserHome, $jekyllCache, $siteDir | Out-Null

Push-Location $docHome
try {
Write-Step "Installing Ruby dependencies"
Invoke-Native -FilePath "bundle" -Arguments @("install")

if ($NoServe) {
Write-Step "Workspace prepared. Run this script again without -NoServe to start Jekyll."
} else {
Write-Step "Starting Jekyll server on port $Port"
Invoke-Native -FilePath "bundle" -Arguments @("exec", "jekyll", "serve", "-P", "$Port", "--trace", "--host=$BindHost", "--livereload", "--destination", "$siteDir")
}
} finally {
Pop-Location
}
Loading