Exemplo n.º 1
0
        private string RewriteLinks(string content)
        {
            // Load the document.
            var document = new HtmlDocument();

            document.LoadHtml(content);

            // Find all links in the document.
            var linkQuery = document.DocumentNode.Descendants("a");

            foreach (var linkNode in linkQuery.ToList())
            {
                if (linkNode.HasAttributes)
                {
                    var url = linkNode.GetAttributeValue("href", "#");
                    if (!url.Equals("#", StringComparison.Ordinal))
                    {
                        var parts = url.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries);
                        if (parts.Length == 2)
                        {
                            var protocol = parts[0];
                            if (protocol != null)
                            {
                                if (protocol.Equals("api", StringComparison.OrdinalIgnoreCase))
                                {
                                    // Resolve the API member.
                                    var data = parts[1].TrimStart('/');

                                    // Update the link.
                                    linkNode.SetAttributeValue("href", _resolver.GetUrl(data) ?? url);
                                }
                                else if (protocol.Equals("dsl", StringComparison.OrdinalIgnoreCase))
                                {
                                    // Resolve the DSL member.
                                    var data = parts[1].TrimStart('/');

                                    // Update the link.
                                    // TODO: Centralize resolving of URL.
                                    var category = _dslModel.FindCategory(data);
                                    var link     = category != null?string.Concat("/dsl/", category.Slug) : url;

                                    linkNode.SetAttributeValue("href", link);
                                }
                                else if (protocol.Equals("docs", StringComparison.OrdinalIgnoreCase))
                                {
                                    // Resolve the documentation id.
                                    var data = parts[1].TrimStart('/');

                                    // Update the link.
                                    linkNode.SetAttributeValue("href", string.Concat("/docs/", data));
                                }
                            }
                        }
                    }
                }
            }

            return(document.DocumentNode.OuterHtml);
        }
Exemplo n.º 2
0
        public ActionResult Index(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(View(_model));
            }

            // Try to find the category.
            var category = _model.FindCategory(path);

            if (category != null)
            {
                return(View("Category", category));
            }

            // The category could not be found.
            var message = $"Could not find DSL category '{path}'.";

            return(HttpNotFound(message));
        }