1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! # link-bridge
//!
//! A lightweight Rust library for creating URL redirects with short names that generate
//! web pages redirecting to longer links on your website.
//!
//! This crate provides a simple and efficient way to create HTML redirect pages that
//! automatically forward users from short, memorable paths to longer URLs on your website.
//! It's perfect for creating user-friendly shortcuts, maintaining backward compatibility
//! after URL changes, or implementing a simple URL shortening system.
//!
//! ## Features
//!
//! - 🚀 **Fast and lightweight** - Minimal dependencies and efficient operation
//! - 🔧 **Simple API** - Easy-to-use interface for creating redirects
//! - 🎯 **URL validation** - Ensures paths contain only valid characters
//! - 📁 **Automatic file management** - Creates directories and HTML files automatically
//! - 📋 **Registry system** - Prevents duplicate redirects and ensures consistency
//! - 🌐 **Standards compliant** - Generates proper HTML5 with multiple redirect methods
//! - 🔒 **Safe** - Built with Rust's memory safety and error handling
//!
//! ## Quick Start
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! link-bridge = "0.2.5"
//! ```
//!
//! ## Basic Usage
//!
//! ```rust
//! use link_bridge::Redirector;
//! use std::fs;
//!
//! // Create a redirector for a URL path
//! let mut redirector = Redirector::new("api/v1/users").unwrap();
//!
//! // Optionally customize the output directory
//! redirector.set_path("redirects");
//!
//! // Generate the redirect HTML file
//! let redirect_path = redirector.write_redirect().unwrap();
//!
//! // Clean up for example
//! fs::remove_dir_all("redirects").ok();
//! ```
//!
//! This creates an HTML file that automatically redirects visitors from your short URL
//! to the longer target path using multiple redirect methods for maximum compatibility.
//!
//! ## How It Works
//!
//! 1. **URL Validation**: Input paths are validated to ensure they contain only safe characters
//! 2. **Unique Naming**: Short file names are generated using base62 encoding and timestamps
//! 3. **Registry Check**: System checks if a redirect for this URL path already exists
//! 4. **HTML Generation**: Complete HTML5 pages are created with multiple redirect methods:
//! - Meta refresh tag (universal browser support)
//! - JavaScript redirect (faster when JS is enabled)
//! - Manual fallback link (accessibility and fail-safe)
//! 5. **File Management**: Directories are created automatically and files are written to disk
//! 6. **Registry Update**: The registry is updated to track the new redirect mapping
//!
//! ## Generated HTML Structure
//!
//! The generated HTML files include:
//!
//! ```html
//! <!DOCTYPE HTML>
//! <html lang="en-US">
//! <head>
//! <meta charset="UTF-8">
//! <meta http-equiv="refresh" content="0; url=/your/target/path/">
//! <script type="text/javascript">
//! window.location.href = "/your/target/path/";
//! </script>
//! <title>Page Redirection</title>
//! </head>
//! <body>
//! If you are not redirected automatically, follow this
//! <a href='/your/target/path/'>link</a>.
//! </body>
//! </html>
//! ```
//!
//! ## Error Handling
//!
//! The library uses the [`RedirectorError`] type for comprehensive error handling:
//!
//! ```rust
//! use link_bridge::{Redirector, RedirectorError};
//!
//! match Redirector::new("invalid?path") {
//! Ok(redirector) => println!("Success!"),
//! Err(RedirectorError::InvalidUrlPath(e)) => {
//! println!("Invalid path: {}", e);
//! }
//! Err(e) => println!("Other error: {}", e),
//! }
//! ```
//!
pub use Redirector;
pub use RedirectorError;