Skip to main content

Content Import

Feature Overview: Content import is iFlow CLI's modular content management system that supports importing external content through @file syntax.

Learning Time: 5-10 minutes

Prerequisites: Understanding basic file path concepts, familiarity with Markdown syntax

What is Content Import

Content import is a modular content management feature provided by iFlow CLI, allowing you to import content from other files using @file.md syntax. This feature enables you to split large configuration files into smaller, more manageable components, achieving modular organization and reuse of content.

Core Features

FeatureDescriptionAdvantage
Modular ManagementSplit large files into small componentsImproves maintainability
Path FlexibilitySupports relative and absolute pathsAdapts to different project structures
Security ProtectionBuilt-in circular import detectionPrevents infinite recursion
Real-time ProcessingDynamic content parsing during importKeeps content synchronized
Cross-project SharingComponents can be reused across projectsImproves development efficiency

How It Works

Import Processing Flow

File Reading → Path Resolution → Security Check → Content Import → Recursive Processing

[@file.md] → [Path Calculation] → [Circular Detection] → [Content Insertion] → [Nested Import]

Security Mechanisms

  • Path Validation: Checks file path legality and security
  • Circular Detection: Prevents circular references between files
  • Permission Control: Ensures only authorized files can be accessed
  • Error Recovery: Graceful handling when imports fail

Detailed Feature Description

Basic Syntax

Use the @ symbol followed by the file path you want to import:

# Main configuration file

This is the main content.

@./components/instructions.md

Here is more content.

@./shared/configuration.md

Supported Path Formats

Path TypeSyntax ExampleDescription
Same directory@./file.mdImport file from same directory
Parent directory@../file.mdImport file from parent directory
Subdirectory@./components/file.mdImport file from subdirectory
Absolute path@/absolute/path/to/file.mdImport using absolute path

Usage Examples

Basic Import Scenarios

Simple File Import

# Main configuration file

Welcome to my project!

@./getting-started.md

## Features

@./features/overview.md

Modular Organization

# Project documentation structure
Project root/
├── IFLOW.md # Main configuration file
├── components/
│ ├── instructions.md # Usage guide component
│ ├── setup.md # Setup guide component
│ └── examples.md # Example code component
└── shared/
├── common.md # Common configuration
└── templates.md # Template files

Advanced Import Features

Nested Import

Imported files can themselves contain imports, creating multi-level structures:

# main.md
@./header.md
@./content.md
@./footer.md
# header.md
# Project Title
@./shared/title.md
@./shared/metadata.md

Conditional Import

Import different configurations based on different situations:

# Development environment configuration
@./configs/development.md

# Production environment configuration
@./configs/production.md

Security Protection Mechanisms

Circular Import Detection

The system automatically detects and prevents circular references between files:

# file-a.md
@./file-b.md

# file-b.md
@./file-a.md <!-- System will detect circular reference and prevent it -->

Detection Mechanism:

  • Maintains import path stack
  • Checks if each new import already exists in the path
  • Immediately aborts and reports error when circular reference is found

Security Restrictions

Security ItemRestrictionPurpose
Path validationOnly authorized directories allowedPrevent access to sensitive files
Depth limitMaximum 5 levels of nestingPrevent infinite recursion
File typesOnly text files supportedAvoid binary file issues
Permission checkVerify read permissionsEnsure file accessibility

Error Handling Strategies

Missing File Handling

  • Graceful failure, doesn't interrupt entire import process
  • Shows friendly error comments in output
  • Logs detailed error information

Permission Error Handling

  • Shows appropriate permission error messages
  • Provides solution suggestions
  • Continues processing other available imports

Format Error Handling

  • Detects file format and encoding issues
  • Provides format fix suggestions
  • Supports multiple text encoding formats

Troubleshooting

Common Issues and Solutions

IssuePossible CauseSolution
Import failureIncorrect file path or file doesn't existCheck file path and file existence
Circular reference errorMutual references between filesCheck and break circular reference chain
Permission deniedInsufficient file read permissionsCheck file permission settings
Depth exceededNesting import levels too deepReduce nesting levels or reorganize structure
Encoding errorUnsupported file encoding formatConvert file encoding to UTF-8

Diagnostic Steps

  1. Path Validation

    • Confirm import path syntax is correct
    • Check relative path base directory
    • Verify absolute path completeness
  2. File Check

    • Confirm target file exists
    • Check file read permissions
    • Verify file encoding format
  3. Structure Analysis

    • Draw import dependency graph
    • Check for circular references
    • Calculate import depth levels
  4. Log Analysis

    • Review detailed error logs
    • Analyze import processing
    • Identify specific failure points

Best Practices

File Organization Recommendations

  • Modular Design: Break content into independent modules by function
  • Hierarchical Structure: Establish clear directory hierarchy
  • Naming Conventions: Use descriptive file and directory names
  • Documentation: Add purpose descriptions for each import module

Maintenance Recommendations

  • Regular Checks: Regularly check import chain integrity
  • Version Control: Include all import files in version control
  • Dependency Documentation: Maintain import dependency relationship documentation
  • Test Validation: Regularly test import functionality correctness

Platform Compatibility

PlatformSupport LevelSpecial Notes
WindowsFull supportPath separators automatically converted
macOSFull supportSupports case-sensitive file systems
LinuxFull supportComplete POSIX path support