diff options
author | vitya-smirnov <[email protected]> | 2025-07-30 11:26:26 +0300 |
---|---|---|
committer | vitya-smirnov <[email protected]> | 2025-07-30 11:38:37 +0300 |
commit | cf9f591e5c90bf964bb922c0f6c3716045972b02 (patch) | |
tree | 36d4eb0816606653836399ac32ea58d2eca08b53 /yql/essentials/utils/docs/resource.cpp | |
parent | ada885655c2e21f6b55e2d3d724e57c9a1fdb843 (diff) |
YQL-20112: Improve dramatically yql/utils/docs
Introduced `links.json` format to link names to
documentation sections. Implement general links
verification framework. Also fixed two small typos.
Extended Description: https://nda.ya.ru/t/zR4voivb7GzD9r.
commit_hash:e72db0e202b4ff612374c73fa384f70d029f0ef0
Diffstat (limited to 'yql/essentials/utils/docs/resource.cpp')
-rw-r--r-- | yql/essentials/utils/docs/resource.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/yql/essentials/utils/docs/resource.cpp b/yql/essentials/utils/docs/resource.cpp new file mode 100644 index 00000000000..8ca724c432e --- /dev/null +++ b/yql/essentials/utils/docs/resource.cpp @@ -0,0 +1,43 @@ +#include "resource.h" + +#include <yql/essentials/utils/yql_panic.h> + +#include <library/cpp/resource/resource.h> + +namespace NYql::NDocs { + + bool IsMatching(const TResourceFilter& filter, TStringBuf key) { + return key.Contains(filter.BaseDirectorySuffix) && + key.EndsWith(filter.CutSuffix); + } + + TStringBuf RelativePath(const TResourceFilter& filter, TStringBuf key Y_LIFETIME_BOUND) { + size_t pos = key.find(filter.BaseDirectorySuffix); + YQL_ENSURE(pos != TString::npos); + pos += filter.BaseDirectorySuffix.size(); + + TStringBuf tail = TStringBuf(key).SubStr(pos); + tail.remove_suffix(filter.CutSuffix.size()); + return tail; + } + + TResourcesByRelativePath FindResources(const TResourceFilter& filter) { + YQL_ENSURE( + filter.BaseDirectorySuffix.EndsWith('/'), + "BaseDirectory should end with '/', but got '" << filter.BaseDirectorySuffix << "'"); + + TResourcesByRelativePath resources; + for (TStringBuf key : NResource::ListAllKeys()) { + if (!key.StartsWith("resfs/file/") || !IsMatching(filter, key)) { + continue; + } + + TStringBuf path = RelativePath(filter, key); + YQL_ENSURE(!resources.contains(path)); + + resources[path] = NResource::Find(key); + } + return resources; + } + +} // namespace NYql::NDocs |